netarky.com

Linux Shell quick reference

Updated 28 Feb 2014

cd
cp
ls
man
mkdir
mv
pwd
rm
touch

 

Ctrl+c cancels the currently executing command
~ is the alias for the path to your home directory
. is the alias for the path to the current directory
.. is the alias for the path to the parent directory
uname -r Shows the current kernel version

cd changes directory
   ~ to the home directory
   - to the previous directory

cd ~
cd /etc/postfix
cd -

cp copies a file or directory
   -R recursively (contents of directories are also copied)
   -i with interactive confirmation
   -v in verbose mode (prints each operation to screen)

cp /etc/postfix/postfix.conf ~/backups/config/
cp ~/backups/config/postfix.conf .
cp ~/backups/config/quickConf.txt /etc/postfix/postfix.conf

ls lists directory contents
   -R recursively (contents of subdirectories are also listed)
   -1 in a single column
   -m comma-separated
   -a showing all files and directories (hidden filenames begin with ".")
   -F showing file type (* executable, / directory, @ symlink, | FIFO, = socket)
   -l in long format
   -r in reverse order
   -X sorted by extension
   -t sorted by date and time
   -S sorted by size
   -h in human-readable form

ls ~
ls -F /etc
ls -laFh

man shows the (help) manual for a command
   -k apropos (shows possible commands based on a search)
   -f gives a brief synopsis of the command
   -u updates (rebuilds) the man pages for a command

man ls
man -k list
man -u ls

mkdir makes a new directory inside the current directory
   -p with parents (simultaneously creates subdirectories)
   -v in verbose mode (prints each operation to screen)

mkdir documents
mkdir -p documents/drafts

mv moves and/or renames a file or directory

mv ~/documents/draft.txt .
mv ~/documents/draft.txt ~/documents/drafts/
mv noname.doc renamed.doc

pwd prints the working directory to screen

rm removes a file or directory

   -R recursively (contents of directories are also deleted)
   -f in force mode (no warnings or questions)
   -i with interactive confirmation
   -v in verbose mode (prints each operation to screen)

rm test.txt
rm -Rf documents/drafts

touch updates a file's access and modification datetimes.
   If no file is specified, a new file is created.
   Thus, touch is also used to create a file.
   -a updates only the access datetime
   -m updates only the modification datetime
   -t lets you specify the update datetime as YYYYMMDDhhmm(ss)

touch
touch -a test.txt
touch -t 201310311200 test.txt