The practical command line cheat sheet
From BITS wiki
Contents
Listing contents
ls -dlh |
List the files and directories with their permissions and size |
|
ls -dalh |
Include hidden files and folders |
|
ls *<word>* |
List files and directories containing the word. |
|
Managing files
mv <filename>{,.back} |
Rename file with <filename> to <filename.back> |
|
rm -rf <files> |
Forcefully remove file. |
|
rm -rf *<string>* |
Forcefully remove files which contain <string> in their name | |
chown -R username:groupname <directory_name/> |
change directory and all its contents to be owned by user username and group groupname. |
|
chmod u+x <file> |
Set the execution permissions to file filename |
|
Searching content
grep <string> <file> |
Display lines in file <file> containing the string <string> | |
grep <string> * |
Search in all files in current directory | |
grep -R <string> * |
Search in all files in current directory and all subdirectories |
|
grep -Rl <string> * |
List the file names in which the string appears |
|
find /usr/local/bin -type l |
Find all symbolic links in the directory /usr/local/bin |
|
find -type d -name bin |
find directories with name bin in current directory. | |
find -name \*.gtf |
find files or directories ending with .gtf. |
|
find . -type f -perm +111 -exec ln -s `pwd`/{} /usr/local/bin \; |
Find in current directory all files with permissions set, and put a symbolic link to them in the folder /usr/local/bin |
|
Storage
ls -lhd * |
List the sizes of the files in current directory |
du -sh * |
List the size of files in current directory |
du -sh */ |
List the sizes of the directories in current directory |
df -h |
List the space left on the storage |
df -h . |
List the space left on the currently used disk |
mount |
Show which disks are available on the system |
showmount -e <host> |
List the NFS network shares offered by host <host> (IP address or hostname) |
Terminal usage
ctrl+shift+T | Fire up the terminal (can be customized of course) |
ctrl+U | clear line |
ctrl+D | close terminal (log out) |
ctrl+a | move to beginning of line |
ctrl+e | move to end of line |
alt+f | move forward one word |
alt+b | move backwards one word |
ctrl+l | clear sceen, leaving current line |
pushd <path_to_dir> | Store the path to the directory <path_to_dir>, and cd to it |
popd | Enter the last stored path with pushd. |
sudo su - | Become superuser. |
Linking
ln -s <what> <towhere> |
Preferentially move first to the folder where to create the symbolic link |
unlink |
Remove a link |