Linux Cheatsheet
Linux Basic Command Line Cheatsheet
This is a cheatsheet of some basic linux commands.
Basic commands
- Navigating, go back, list directories, print working directory.
1 2 3 4
cd /Users/Hello/Documents/ cd .. ls pwd
- Create a file. If already exists, then select that file or directory.
1
touch example.txt
- Create a directory.
1
mkdir example_folder
- Move file to directory.
1
mv example.txt ./example_folder/example.txt
- Remove file, remove directory.
1 2
rm example.txt rmdir example_folder
List User. cat /etc/passwd
- Permissioning: change ownership of a folder.
1
sudo chown stephen ./example_folder
- Grant permission to execute a file.
1
chmod 700 example.ch
- Editing a file using Vim.
1
vim example.txt
- Basic Vim commands:
1 2 3 4 5 6
Press i to enter insert mode. Press esc to go back to command mode. Type :w followed by enter to save. Type :q followed by enter to quit. Type :q! followed by enter to force quit. Type gg dG to delete all.
- Delete Swap Files:
1
find . -type f -name "*.sw[klmnop]" -delete
- Check if a process is still running:
1
ps aux | grep <script_name>
Here are the different states:
- R: Running
- S: Sleeping
- T: Stopped
- Z: Zombie (terminated but not fully cleaned up)
- D: Uninterruptible sleep (usually related to I/O operations)
- To kill a process use the following. Note, in general, you don’t want to kill a process in the
S+
state because it is waiting for an event to complete.1
kill <Process ID>
To force kill all events associated with your script:
1
pkill -f <script_name>
Ubuntu
- Updating Ubuntu.
1 2 3
sudo apt update sudo apt full-upgrade sudo apt-get dist-upgrade
- Auto-installing critical updates.
1 2
sudo apt-get install unattended-upgrades -y sudo dpkg-reconfigure -plow unattended-upgrades
- Clean system:
1 2
su - apt autoremove -y && apt autoclean && apt clean
This post is licensed under CC BY 4.0 by the author.