This how-to describes various UNIX/LINUX commands. I have found these commands useful over the years.

Misc Commands

Command

Description

ps -efList all running processes
ps -efwwList all running processes and wrap to screen

<cmd> &>/dev/null

<cmd> >/dev/null 2>&1

Redirect all output to /dev/null
<cmd> >/dev/nullRedirect stdout to /dev/null
<cmd> 2>/dev/nullRedirect stderr to /dev/null
cat <file> | grep -v '<string1>/|<string2>'Exclude lines with 2 strings from output

find . -name <filename>

Searches the file system for specified file.

find . |grep <search>Search for a file
<cmd> | grep -v <string>Output lines not containing string
<cmd> | grep -v '<string1>/|<string2>'Output lines not containing any of the strings
historyshow command history
!<##>execute command # from history
!<start of command>execute command from history starting with.
CTRL-RSearch command history

lsof -P |grep LISTEN

Display ports that your machine is listening on.

Uses lsof (list open files)mockser

dd if=<file> of=<file> [ bs=# ] [ count=# ]dd copies what is specified in the input file (if) to the output file (of). bs= is the block size (bytes) and count= is the number of blocks to copy. See man dd for more informations.
tar x|c|t [ z | Z | j ] [ f <file> ] <tar_file>

tar is an archiver. You can use it to expand (x), create (c) or test (see the content, t) of tar archives. If f option is specified, it will tell which file is the input (for x and t) or the output (for c). There are ways to also use compression with options:

  • z : gzip
  • Z : compress
  • j : bzip2

See man tar for more information. There are a lot of more options and very useful functions like destination directory when unarchiving or directory to include when creating (C), other ways of compression and the interactive mode (that allows to choose what should be unarchived).


sudo parted <img> unit B print

Print out the partition information of the image

ie. 

> sudo parted new.img unit B print

Model: (file)
Disk /home/test/projects/sabrelite_demo/new.img: 1795162112B
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number Start End Size Type File system Flags
1 4194304B 25165823B 20971520B primary fat16 boot, lba
2 25165824B 1266679807B 1241513984B primary ext3
3 1266679808B 1790967807B 524288000B primary ext3

sudo mount -o loop,offset=<offset_in_bytes> <img> <folder>


Specify the filesystem type:

-t <fsType>

  • auto - this is a special one. It will try to guess the fs type when you use this.
  • ext4 - this is probably the most common Linux fs type of the last few years
  • ext3 - this is the most common Linux fs type from a couple years back
  • ntfs - this is the most common Windows fs type or larger external hard drives
  • vfat - this is the most common fs type used for smaller external hard drives
  • exfat - is also a file system option commonly found on USB flash drives and other external drives

Mount a partition to a directory

ie. sudo mount -o loop,offset=4194304 new.img p1


ie. sudo mount -t ext4 -o loop,offset=63963136 my_image.img p2

dd if=/dev/zero of=<image> bs=1M count=100Create a blank image file
mkfs.ext3Make file system ext3
lsusblist usb devices

rsync -avP <source> <dest>


using ssh with non-standard port:

rsync -arP -e 'ssh -p <port>' <source> <dest>


To resume a failed transfer:

rsync --append ....

Archive all files from one folder to another.


Over SSH Example:

$ rsync -av pi@192.168.1.201:~/RetroPie/roms .


$ rsync -arP -e 'ssh -p 7777' admin@192.168.1.60:/share/folder .


Command

Description

Example

bless <file>hex editor> bless ~/file.bin
mountList mounts> sudo mount
mount -aRe-mount 
umount <mount_point>Unmount> sudo umount /home/test/projects/yas-arm/run/partition_1
diskutil -lList partitions> sudo diskutil -l
lsblkList disks and partitions

> sudo lsblk

sudo lsblk 
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 80G 0 disk 
├─sda1 8:1 0 77G 0 part /
├─sda2 8:2 0 1K 0 part 
└─sda5 8:5 0 3G 0 part [SWAP]
sdb 8:16 1 3.5G 0 disk 
├─sdb1 8:17 1 8M 0 part 
├─sdb2 8:18 1 1.2G 0 part 
└─sdb3 8:19 1 500M 0 part 
sr0 11:0 1 1024M 0 rom

kill -STOP <processId>Pause a process> sudo kill -STOP 208
kill -CONT <processId>Resume a process> sudo kill -CONT 208
nm <exe>View executable symbols. Needed for debugging. > nm rdTest
minicom -ssetup minicom
arp -a List Mac/ip addresses on network

arp -a

OUTPUT: 

appletv-livingroom.jmehan.com (192.168.1.33) at c8:d0:83:e5:98:3 on en0 ifscope [ethernet]

pihole.jmehan.com (192.168.1.51) at d0:ca:ab:cd:ef:1 on en0 ifscope [ethernet]

...

type CMD
display cached location of command> type cfssl
cfssl is hashed (/usr/local/bin/cfssl)
hash -r
clear cache of all commands> hash -r 
hash -d CMD
remove command location from cache> hash -d cfssl

Apt-get Commands

Command

Description

apt-get updateupdate apt-get info
apt-cache search <keyword>
search the list of available packages
apt-get install <application>install application
apt-get remove -V <application>remove application
apt-cache policy <application>show versions
apt-get install -y -q 
  docker-engine=1.11.1-0~trusty
Install a particular version of docker
  • No labels