DEV Community

Cover image for Lists of Common Linux Commands
joseph4real
joseph4real

Posted on

Lists of Common Linux Commands

sudo su command: - is often used to switch to the superuser or root account to perform administrative tasks. This command stands for “superuser do,” and it lets you act as a superuser or root user while you’re running a specific command. It’s how Linux protects itself and prevents users from accidentally modifying the machine’s filesystem or installing inappropriate packages. Sudo is commonly used to install software or to edit files outside the user’s home directory: It’ll ask you for the administrator’s password before running the command you typed after it.

Image description
apt update command:-The command apt-get update is used to update the package index files on the system, which contain information about available packages and their versions. It downloads the most recent package information from the sources listed in the "/etc/apt/sources. list" file that contains your sources list. To update the packages using apt-get update use the following command:
apt-get update/apt update

Image description

apt install : - This command allows you to install packages from the distribution's software repositories. After typing "apt install," you would typically provide the name of the package you wish to install. For example, to install the "nginx" package, you would use the following command:
apt install azure-cli

Image description
ls Command:-ls is probably the first command every Linux user typed in their terminal. It allows you to list the contents of the directory you want (the cucd rrent directory by default), including files and other nested directories.

Image description

pwd Command:-The pwd command stands for “print working directory,” and it outputs the absolute path of the directory you’re in. For example, if your username is “john” and you’re in your Documents directory, its absolute path would be: /home/john/Documents.

Image description
cd Command:- It refers to “change directory” and, as its name suggests, switches you to the directory you’re trying to access. The cd command is highly popular, along with ls. For instance, if you’re inside your Documents directory and you’re trying to access one of its subfolders called Documents, you can enter it by typing:
cd Desktop

Image description

You can also supply the absolute path of the folder
cd /home/joeubuntu/Documents

Image description

There are some tricks with the cd command that can save you a lot of time when playing around with it:
1) Go to the home folder: type cd+one space
Cd

Image description
2) Move a level up: documents folder is removed from /home/joeubuntu/Documents
cd ..

Image description

3) Return to the previous directory
cd –

Image description
mkdir Command:- The command is use to create folders, i.e to make directory folder. Just specify the new folder’s name, ensure it doesn’t exist, and you’re ready to go. For example, to make a directory to keep all of your images, just type:
mkdir Films/

Image description

To create subdirectories with a simple command, use the parent (-p) flag:
mkdir -p Films/2004/

Image description

Vim Command :- it’s a command use to create, make and edit a next file. To create a file use
To make a file and Edit (follow the below description)
a. Input vim my name (my name text doc created).

Image description

b. To edit:- Blank space will be opened, press “I” on the keyboard to enable “editing” i.e. INSERT texts to the file.

Image description
c. Press the ESC button to leave the inert mode.
d. To save, press Shift colon and type :wq and enter. File saved,

Image description

e. To exit or quit. Do control C, then type :qa and enter
Note: touch and nano commands can also be used to create txt files in Linux.

Image description
Touch :- to create a file: use touch file1.txt file2.txt file3.txt

Image description
cp Command:- It’s use to copy files and folders directly from one directory to another. In the Linux terminal, sometimes it can replace conventional file managers. To use the cp command, just type it along with the source and destination files:
cp my.txt file1.txt

Image description
The command “cp” copy content (this how to use vim) from file “my” to “file1.txt”.
cp file1.txt tests

Image description
The command above copied text file file1.txt to tests folder.

rm Command:- You can use the rm command to remove files and directories. Be careful while using it, though, because it’s very difficult (yet not impossible) to recover files deleted this way.
To delete a regular file, you’d type:
rm file2.txt

Image description
If you want to delete an empty directory, you can use the recursive (-r) flag:
rm -r Films/

Image description
On the other hand, to remove a directory with content inside of it, you need to use the force (-f) and recursive flags:
rm -rf tests/
Tests dir
with content*_ file1.txt_*

Image description
No more tests directory.

Image description
cat Command:- Use to view the contents of a text file.
Cat

Image description
Exit command:- use to terminate terminal current section and return to the root environment.

Image description
Clear command:- its use to clear screen or the terminal content.

Image description
After executing the clear command.

Image description

History command:- its to display lists of already executed commands, i.e. previous commands executed.

Image description

   LETTER OF CONGRATULATION TO MYSELF
Enter fullscreen mode Exit fullscreen mode

Image description

Top comments (0)