Cheatography
https://cheatography.com
This is a cheatsheet for Linux OS
This is a draft cheat sheet. It is a work in progress and is not finished yet.
Linux
To create a folder |
mkdir <folder_name> |
To get into a folder |
cd <folder_name> |
To create a file |
vim <file name> |
To display the contents of a file |
cat <file name> |
Handy commands
To get into a folder |
cd <folder name> |
To get the list of available files and folders in a directory |
ls |
To get the current logged in user |
whoami |
To get the present working directory |
pwd |
To get the list of all commands used |
history |
To clear screen |
clear |
To get date and time |
date |
To get kernel name |
uname |
To get kernel version |
uname -r |
TO get manual of a command |
man <command name> |
Copy / Move
To copy a file |
cp <option> <source> <destination> |
To delete a file |
rm <option> <path to the file>> |
To move/rename a file |
mv <source> <destination> |
User management
To add a new user account |
sudo useradd <user name> |
To create a password to the user account |
sudo passwd <user name> |
To create a new group |
sudo group add <group name> |
To add user to a group |
sudo gpasswd -a <user name> <group name> |
To delete a user |
sudo userdel <user name> |
To delete a group |
sudo groupdel <group name> |
|
|
File permissions
To change permission |
chmod <mode> <file/directory> |
To change ownership |
chown <owner> <file/directory> |
To change group ownership |
chgrp <group name> <file/directory> |
Access Control Lists(ACL)
To get ACL entries of a file or directory |
getfacl <file/directory> |
To set ACL to a file/folder |
setfacl -m u:username:permissions <file/directory> |
To remove ACL of a user |
setfacl -x u:username:permissions <file/directory> |
To set ACL of a group |
setfacl -m g:groupname:permissions <file/directory> |
To remove ACL of a group |
setfacl -x g:groupname:permissions <file/directory> |
|
Tp set ACL |
setfacl [options] -m u:username:permissions file/directory |
Gloal regular expressions Print<
Case-insensitive pattern search |
grep <pattern><file_name> |
Display line numbers |
grep -n <pattern> <file> |
Search recursively in directories |
grep -r <pattern> <directory> |
Regular expression search |
grep -E <string/expression> file |
Search recursively in directories: |
grep -r <string/expression> /path/to/directory |
Find
Find files by name |
find /path/to/directory -name "*.txt" |
Find directories |
find /path/to/directory -type d |
Display bottom few line of code |
tail -n <no of lines to display><file name> |
Display top few line of code |
tail -n <no of lines to display><file name> |
Create a tar archive |
tar -cvf <tar archive file> <path to file or folder to be archived> |
Awk command syntax |
awk 'pattern { action }' input_file |
|