In all operating systems, including Linux, the term “command” means either a command-line utility or a specific feature built into the system’s command shell. You enter a command in the terminal emulator and get the result of its execution.
Now let’s look at some basic utilities that everyone needs to know in order to effectively use BASH. Let’s go!
LS is an utility for viewing the contents of directories. Displays the current directory by default. If you specify the path to a folder in the parameters, it displays the contents of this folder.
-a shows all files and directories, including hidden ones
-l formats the output as a list with more detailed information
*.m shows all files with the extension “.m”
*My* shows all files and folders with names that contain “ My”
ls -a -l /usr/share/applications/
CD is an utility for switching from the current directory to the specified one. If you run it without parameters- it returns it to the home directory. A call with two dots
cd .. returns a level up relative to the current directory. Calling with a dash
cd - returns to the previous directory.
.. returns a level up relative to the current directory
- returns to the previous directory
MKDIR is an utility for creating a new directory.
-p creates a subdirectory structure, even if they don’t exist
mkdir -p /home/dmfrpro/Projects/DemoProject/resources
TOUCH is an utility for creating a file. Using different options, you can change its properties, but we will talk about this in more detail in other articles.
CP is an utility for copying files and directories to the specified directory. To copy a directory with all the files in it, you need to specify the
-r key for recursive copying.
cp path/to/file path/to/destination/file
cp path/to/directory/ path/to/destination/directory
-r recursively copies the files in the directory
-a saves user permissions
cp 1.log Logs/Android/1.log
cp -r -a /home/dmfrpro/Logs /home/dmfrpro/Backup
MV is an utility for moving (cut-paste) files and directories to the specified directory. To move a directory with all the files in it, you need to specify the
-r key for recursive movement. The same command is used to rename files.
mv path/to/file path/to/destination/file
mv path/to/directory/ path/to/destination/directory
mv old_file_name new_file_name
-r recursively moves the files in the directory
-a saves user permissions
mv 1.log Logs/Android/
mv -r -a /home/dmfrpro/Logs /home/dmfrpro/Backup
mv 1.log 2.log
RM is an utility for deleting files and directories. To delete a directory with all the files in it, you need to specify the
-r key for recursive deletion. Be careful when deleting files with superuser rights, as you can delete system files.
-r recursively deletes the files in the directory
-rf recursive forcibly removes the files in the directory
rm -r /Backups
rm -rf /home/dmfrpro/Projects
FIND is an utility for searching files and directories.
find path/to/directory/ --name file_name_or_directory_name
. search in the current directory
find . -name *.log
find / -name home
find /home/dmfrpro/ -name *Class*.txt
CAT and TAC
CAT is utility that prints the contents of a file to the console or to a file. TAC prints the content from the end to the beginning.
cat file name
cat path/to/file_name_1 path/to/file_name_2
tac 1.log Backups/2.log
cat 1.log 2.log Backups/3.log
ECHO is an utility that prints a line to the console or a file.
echo “string” > path/to/file # prints the string to the file, pre-creating the file if it is not there
echo “hello world”
echo “hello world” > 1.log
MAN is an utility that prints a manual for a given command to the console.
PING is an utility that prints ping (the delay in connecting to servers). Often used to check your internet connection.
SU and SUDO
SU is an utility that grants the user a superuser rights. SUDO only executes a command once on behalf of the superuser. Be careful when working with superuser rights!
sudo mount /dev/sda1 /mnt
PUSHD and POPD
PUSHD is an utility similar to CD, but allowing you to remember the previous path. After its execution, two paths are output separated by a space: the new and the old.
With the POPD command, you can return to the old path from which the transition was made.
/a$ pushd b