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 |
find . -name <filename>
Searches the file system for specified file.
<cmd> &>/dev/null <cmd> >/dev/null |
2>&1 | Redirect all output to |
This how-to describes various UNIX/LINUX commands. I have found these commands useful over the years.
Misc Commands
Command
Description
/dev/null |
lsof -P |grep LISTEN
Display ports that your machine is listening on.
Uses lsof (list open files)mockser
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).
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
rsync -av <source> <dest>
Archive all files from one folder to another.
Command
Description
Example
> 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
Apt-get Commands
...
Command
...
Description
...
apt-cache search <keyword>
...
apt-get install -y -q
docker-engine=1.11.1-0~trusty
...
<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 |
<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 -av <source> <dest> | Archive all files from one folder to another. |
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 |
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 |
...