My Linux command quick reference

My day-to-day job does not involve Linux, so I made a command reference for me. Some useful nix commands:

list directory contents
list directory contents wish permissions, dates, size, etc.
ls -l
print (name of) working directory
text editor
copy file
copy directory
cp -r
move or rename file or directory
create directory
delete file or directory
delete non-empty directory
rm -r dir_nameorrm -ir dir_name [confirm everything]
process list
free space on all hdd
df -h
1. Owner
2. Group
3. World

0 --- no permissions
1 --x execute
2 -w- write
3 -wx write, execute (1+2)
4 r-- read
5 r-x read, execute (4+1)
6 rw- read, write (4+2)
7 rwx read, write, execute (4+2+1)

permission examples
chmod 700 some_file - you read, write, execute
chmod 777 some_file - everyone read, write, execute
chmod 744 some_file - you read, write, execute; everyone read
chmod 444 some_file - you read, everyone else

show (type) file in console
cat fileorcat file1 file2
if file is very long
cat file | moreorcat file | lessorless file
show last part of file
tail file
show first part of file
head file

Windows tracert

Show the full path of (shell) command
which command

To locate the binary, source, and manual page files for a command
whereis command

To gzip output
cat somefile | gzip -9 > filename.gz

To archive directory to TAR
tar cf archive_name.tar directory/to/archive/

To archive directory to tar.gz
tar czf archive_name.tar.gz directory/to/archive/

To archive directory to tar.bz2
tar cjf archive_name.tar.bz2 directory/to/archive/

How to change Ubuntu Server from dynamic address (DHCP) to a static IP address?

You need to change addresses into following files:

  • /etc/network/interfaces
  • /etc/resolv.conf

The following article from prefers vi editor, but I use nano editor.
sudo nano /etc/network/interfaces

change to something like this
iface eth0 inet static

and DNS settings
sudo nano /etc/resolv.conf
and then restart
sudo /etc/init.d/networking restart

If you have DHCP client enabled, you must disable it. Consult the following article for more details:

Ubuntu DHCP to a Static IP Address

Real men don't make backups