Here is a list of most frequently used Linux commands
Trying to find the right Linux shell command for your VPS on the internet is time consuming. I often find myself looking for the same commands again and again. To fix this, I have created a list of most common Linux commands for my self that is easily accessible. It’s my Linux Shell Commands Cheat Sheet. I will keep adding to this list over the time and hope fully it will keep expanding and will benefit some of you as well.
Copy files and folders in Linux with shell commands
One of the most common Linux command is “cp” command that helps copy files or folders. Use the “cp” copy command followed by the target file/folder which is followed by the destination file/folder.
cp -option source_path destination_path
Copy a directory to another directory
cp -r /home/test /home/test2/
Copy all the files from a directory to another directory
cp -r /home/test/* /home/test2/
Move files and folders in Linux with shell commands
To move files and folders in Linux Bash, you can use the mv
command. Here’s the basic syntax:
mv source_path destination_path
Move a single file
mv /home/index.html /home/home.html
Note: moving within the same folder renames the file so ‘mv’ command is also used for renaming files and folders
Move a single file to different location
mv /home/website_1/index.html /home/website_2/index.html
File is moved from website_1 folder to website_2 folder
Move a folder to different location
mv /home/website_1/images /home/website_2/
Images folder is moved from website_1 folder to website_2 folder
Move a folder to different location and rename it
mv /home/website_1/images /home/website_2/images2
Images folder is moved from website_1 folder to website_2 folder and renamed to images2
Move a multiple folders to different location
cd /home/website_1
mv images css js /home/website_2/
Images, js and css folders are moved from website_1 folder to website_2 folder
Move all files and folders from one location to another location
mv /home/website_1/* /home/webstie_2
All files and folders are moved from website_1 folder to website_2 folder
Use -i option to prompt if file folder already exists
mv -i /home/website_1/* /home/webstie_2
If a file or folder already exists at the destination it will prompt for confirmation
Zip and Unzip files and directories in Linux with shell commands
Compressing/uncompressing files and folder is very common when moving content or migrating websites. Zip and unzip is one of the most common methods to compress and move data.
How to Install Zip and Unzip on Centos/RedHat
yum install zip unzip
How to Install Zip and Unzip on Ubuntu
apt install zip unzip
Compress files and directories with Zip command
zip – r <compressed file name> <file or directory that need to be compressed>
Compress a file with Zip
zip -r /root/movie.zip /home/website_1/media/movie.mpeg
This will compress the file movie.mpeg and put it under /root directory as movie.zip
Compress a folder with Zip
zip -r /root/website1.zip /home/website_1
This will compress the contents of website_1 directory and put it under /root directory as website1.zip
Remove files and directories
You can easily delete files and folders using the rm command
Remove a file
rm filename.ext
Remove multiple files
rm filename.ext filename.txt filename.png
Remove a directory and all of it’s contents using -r
rm -r directoryName
Force remove a directory using -f to remove write protected files
rm -rf directoryName
Remove everything within the directory you are in
rm -rf *
Remove every file with a certain extention
rm *.txt