Help on command | |
---|---|
man <cmd> | Type man ls to read the manual for the ls command |
Navigate between directories | |
ls -ltrah <path> | List contents of the directory <path> including entries starting with `. ` in the long listing format with human readable size like 2G rather than 2146858929 and sorted by their modification date, oldest first. |
cd <path> | Change the current directory to <path> |
pwd | Show the absolute path of the current directory |
Special directories | |
~ | Home directory |
. | Current directory |
.. | Parent directory |
Modify directories | |
mkdir -p <path> | Make a new directory with the path <path> . Missing parent directories along the path will be created. |
cp <file> <dst> | Copy the file <file> to the destination <dst> . If <dst> is a directory, the new file will be created inside it. |
cp -r <dir1> <dir2> | Copy directory dir1 and all its contents recursively as/to <dir2>. If <dir2> exists, the new directory will be created inside <dir2> . |
mv <file> <dst> | Move the file <file> to the destination <dst> . If <dst> is a directory, the file will be moved inside it. |
rm <file> | Remove files. “?” is any character; “*” is any string of characters. |
Connect/Copy files to remote host | |
ssh <user>@gadi.nci.org.au | Login to Gadi as the user <user> |
scp <file> <user>@gadi-dm.nci.org.au:<dst> | Copy local <file> to Gadi into the directory <dst> or as the file <dst> |
View/Edit a text file | |
less <file> | View <file> with less |
cat <file> | Print <file> on screen |
vim <file> | Edit <file > with vim |
emacs <file> | Edit <file > with emacs |
Compress files | |
tar czf file.tar.gz <folder> | Create the compressed archive <file.tar.gz> with gzip for all contents in the folder <folder> (use xzf to extract) |
gzip <file> | Compresses file and renames it to file.gz |
Other useful commands | |
diff -y <file1> <file2> | Show the differences between <file1> and <file2> side-by-side |
grep -n "str" <file> | Print lines containing the string str in <file> with the prefix of its line number |
awk -F, '{print $4}' <file> | Print the fourth column of comma delimited table in <file> |
wc -l <file> | Count lines in the file <file> |
find <path> -type d -name *1234* | Search through the directory <path> for directories with name containing the string 1234 |
File access permissions | |
chmod g+w <file> | Add group writable permission to the file <file> |
chgrp -R <prj> <path> | Set the owner group of the directory <path> and its contents to the project <prj> recursively. |
getfacl <file> | Get file access control lists of the file <file> |
Pipes and redirection | |
ls -l > list.txt | List the content of the current directory and redirect the output to the file list.txt. If file list.txt exists, overwrite it with the output. |
<cmd> >> <file> | Append output of the command <cmd> to the file <file> |
<cmd> < <file> | Get input of the command <cmd> from the file <file> |
<cmd1> | <cmd2> | Pipe the output of command <cmd1> to the standard input of command <cmd2> |
Shortcuts | |
Ctrl+C | Halt the current command |
Ctrl+A | Move cursor to the beginning of the line |
Ctrl+E | Move cursor to the end of the line |
Ctrl+K | Delete from cursor to the end of the line |
Ctrl+Z | Stop the foreground job and places it in the background as a stopped job |
Ctrl+D | Log out of current session, similar to exit |