This how-to describes various UNIX/LINUX commands. I have found these commands useful over the years.
Misc Commands
Command | Description |
---|---|
ps -ef | List all running processes |
ps -efww | List all running processes and wrap to screen |
<cmd> &>/dev/null <cmd> >/dev/null 2>&1 | Redirect all output to /dev/null |
<cmd> >/dev/null | Redirect stdout to /dev/null |
<cmd> 2>/dev/null | Redirect 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 |
find . -type f -size +10G | Search for files larger then ... |
<cmd> | grep -v <string> | Output lines not containing string |
<cmd> | grep -v '<string1>/|<string2>' | Output lines not containing any of the strings |
history | show command history |
!<##> | execute command # from history |
!<start of command> | execute command from history starting with. |
CTRL-R | Search 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:
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) Number Start End Size Type File system Flags |
sudo mount -o loop,offset=<offset_in_bytes> <img> <folder> Specify the filesystem type: -t <fsType>
| 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=100 | Create a blank image file |
mkfs.ext3 | Make file system ext3 |
lsusb | list 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 |
mount | List mounts | > sudo mount |
mount -a | Re-mount | |
umount <mount_point> | Unmount | > sudo umount /home/test/projects/yas-arm/run/partition_1 |
diskutil -l | List partitions | > sudo diskutil -l |
lsblk | List disks and partitions | > sudo lsblk sudo lsblk |
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 -s | setup 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] ... |
| display cached location of command | > type cfssl |
| clear cache of all commands | > hash -r |
| remove command location from cache | > hash -d cfssl |
Apt-get Commands
Command | Description |
---|---|
apt-get update | update apt-get info |
| 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 |