If you have started learning useful Linux commands, you have probably already installed one of the distributions of this operating system and are ready to work productively. In this article, we will list the most common useful commands for Linux users.
Overview of useful Linux commands
pwd (Print Working Directory)
This command displays the current directory you are in. It is especially useful if you forget where you are in the file system.
pwd
Result
/home/user/documents
ls (List)
When used without parameters, this command displays a list of all files and folders in the current directory. To display the contents of another directory without changing to it, simply specify the path to the desired directory:
ls /home/user/documents
Result
file1.txt image.png projects/
Command options
Display hidden files
ls -a
Result
.profile Documents Downloads #результат
Conclusion of such information
ls -l
Result
drwxr-xr-x 2 user user 4096 Mar 5 10:00 Documents
-rw-r--r-- 1 user user 1024 Mar 5 09:30 file.txt
File size output
ls -lh
Result
-rw-r--r-- 1 user user 1.2M Mar 5 09:30 large_file.mp4
Extracting files of a specific type
ls *.txt
Sort by size
ls -lS
Counting the number of files
ls | wc -l
cd (Change Directory)
This command allows you to navigate to another directory. For example:
cd /home/user/Documents
Command options
Go to home folder
cd
Moving up a level
cd ..
Go to the root directory
cd /
Go to the previous catalog
cd -
Moving to a folder with spaces in its name
cd "My Documents"
Switch to user directory
cd ~alex
touch
Allows you to create an empty file with the specified name. To make sure that the file has been created in the right place, use the ls command. Example:
touch example.txt
rm (Remove)
This command deletes unnecessary files. Be careful, as deletion is irreversible. For example:
rm example.txt
mkdir (Make Directory)
Used to create new folders. Example:
mkdir examplefolder
rmdir (Remove Directory)
Allows you to delete an empty folder. For example:
rmdir examplefolder
mv (Move)
Command for moving files and folders, as well as renaming them.
Moving a file:
mv example.txt /new/folder/
Renaming a file
mv oldname.txt newname.txt
cp (Copy)
Used to copy files and folders. You can specify a new name for the copy. Example:
cp example.txt copy_example.txt
cp file1.txt /home/user/Documents/
man (Manual)
The command opens reference information about any other command. For example:
man ls
Conclusion
These commands form the basis of working in Linux, helping you to manage files and directories efficiently. It should be noted that each command is responsible for more than just the actions listed. In fact, they can do much more. We have only described some of the most commonly used features. In addition, if you want to work in Linux, you should also learn about file access permissions.