Linux Cheat Sheet - Click on this link to see more details.
Linux Cheat Sheet | |
List Commands | |
ls -l | list the files and directories in long list format with extra information |
ls -a | list all including hidden files and directory |
ls *.sh | list all the files having .sh specific extension. |
Change Directory Commands | |
pwd | present working directory. |
cd path_to_directory | Change directory to the provided path |
cd ~ or just cd | Change directory to the home directory : /home/ubuntu/ |
cd .. | Change directory to one directory back. |
cd ../.. | Change directory to 2 directory back. |
File | |
touch filename | Create empty/blank file |
touch filename.txt | Create empty/blank file with extension |
touch file{1..100}.txt | Create 100 text file in one go |
touch .file | Create hidden file |
vim filename | Create and edit the file |
cat filename | See the content of the file |
echo "Hello" >> filename.ext | Print the output message in the file |
head -n 3 fruits.txt | To see the top 3 lines in fruits.txt |
tail -n 3 Colors.txt | To see the last 3 lines in Colors.txt |
diff fruits.txt Colors.txt | To see difference between two files |
Directory | |
mkdir DirectoryName | To make a directory in a specific location |
mkdir .NewFolder | make a hidden directory (also . before a file to make it hidden) |
mkdir A B C D | make multiple directories at the same time |
mkdir /home/user/Mydirectory | make a new folder in a specific location |
mkdir -p A/B/C/D | make a nested directory -p = parent |
mkdir dir{1..99} | To make multiple directories in one go |
Remove File and Directory | |
rm filename | To remove file |
rmdir DirectoryName | To remove Empty directory |
rmdir -rf DirectoryName | To remove a Directory with files in it |
System Information | |
hostname | Shows the name of the system host. |
sudo | Run commands as security privileges of superuser or root |
clear | Clears the terminal; no old commands on screen |
history | Displays the list of all the typed commands on terminal |
whoami | This command displays the name with which you are logged in. |
Create User | |
sudo useradd username | Creating new user |
sudo useradd -m username | Creating new user with its home directory |
sudo passwd username | Setting password to user |
cat /etc/passwd | See user info |
Delete User | |
sudo userdel username | Delete user |
sudo userdel -r username | Delete user with directory of the user |
sudo deluser user1 group1 | Remove user from specific group |
Create Goup | |
sudo groupadd groupname | Create a group |
sudo adduser user123 group123 | Adding user to a group |
cat /etc/group | See group info |
sudo usermod -aG docker ubuntu | Adding ubuntu user in docker group -a append |
sudo usermod –aG group1, group2, group3 commonuser | Add a user to multiple groups at once |
Delete Group | |
sudo groupdel group1 |
|
Change Ownership | |
chown <user_name> <file_name> | To change file or directory ownership |
chgrp <group_name> <file_name> | To change group ownership |
File Permission | |
chmod <permission> <file_name> | To change permission of the file |
chmod 700 file1.txt | To give rwx permission to owner of the file |
chmod u+wx file1.log | To add read and execute permission for user |
chmod ugo+rwx foldername | To give read, write, and execute to everyone. |
chmod a=r foldername | To give only read permission for everyone. |
chmod o-rwx foldername | To remove read write & exec permission for other |
Access Control List | |
getfacl <file or directory name> | Get the current permission status |
setfacl -m u:abcuser:rwx test/declarations.sh | To add permission for user -m : modify |
setfacl -m g:groupName:permissions /path/to/file | To add permissions for a group |
setfacl -x u:user:w /path/to/file | To remove write ACL permission of user: -x = remove |
Server Level Commands | |
top | Get the details of all active processes. |
ps | Give the status of running processes for a user |
free -h | Display the free and used memory; -h human-readable form |
cat /proc/meminfo | Information about memory like total and occupied |
du | Disk usage of a file or directory |