DEV Community

Dipsan Kadariya
Dipsan Kadariya

Posted on • Updated on

Linux Basics πŸ“‚ | Essential Commands Every Beginner Should Know πŸ“

  1. Sudo su

Terminal showing sudo su command

"sudo" stands for "superuser do". It allows a permitted user to execute a command as the superuser or another user.
"su" stands for "switch user".
The hyphen (-) at the end is a shorthand for "-l" or "--login", which provides a full login shell.
(This is just for knowing, not necessary used for now)...just knowing is good.

  1. pwd (Print Working Directory)

Terminal showing pwd command and output

The pwd command shows your current location in the file system.

  1. ls (List Directory Contents)

Terminal showing ls command and output

The ls command lists files and directories in your current location.

  1. ls -la (Detailed List View)

Terminal showing ls -la command and detailed output

Adding the -la options to ls provides a detailed, long-format list that includes hidden files, hidden files have "." in front of them.

  1. cd (Change Directory)

Terminal showing cd command changing to Desktop directory

Initially we were in /home/kali, when we write cd Desktop, path changes to /home/kali/Desktop.

  1. cd .. (Reverse Directory)

Terminal showing cd .. command moving back to parent directory

  • This command helps to go back to the previous directory.
  • Let's say you are in Desktop directory but you want to go back to kali directory
  • You can do it by typing:
  cd ..
Enter fullscreen mode Exit fullscreen mode
  1. Mkdir (Make a new Subdirectory)

Terminal showing mkdir command creating a new directory

  • It is used to make a new folder. Let's make a new folder in the Desktop by first changing the directory to Desktop, and typing:
  mkdir filename
Enter fullscreen mode Exit fullscreen mode

Example:

  mkdir helloworld
Enter fullscreen mode Exit fullscreen mode

This will create a folder named helloworld in the Desktop.

  1. touch

Terminal showing touch command creating a new file

  • The primary purpose of the touch command is to update the access and/or modification date of a file or directory. However, it can also be used to create a file if it doesn't exist.
  • Let's create a file named file.txt in the helloworld folder. The first step would be changing the directory to the helloworld folder if not done, then typing:
  touch file.txt
Enter fullscreen mode Exit fullscreen mode
  1. cp (copy)

Terminal showing cp command copying a file

  • Let's say we want to copy the file.txt to a new folder named "newfolder", we can do it by first creating a newfolder in the desktop, now the desktop will have two folders, one being the helloworld folder which contains the file.txt and a new empty folder named "newfolder"
  • To copy the file.txt what we can do is, type:
  cp ~/Desktop/helloworld/file.txt ~/Desktop/newfolder/
Enter fullscreen mode Exit fullscreen mode

Basically what we are doing is, taking the path of the file.txt i.e. ~/Desktop/helloworld/file.txt (which is inside helloworld folder in desktop) and copying it to where we want to copy it, i.e. ~/Desktop/newfolder/ (inside newfolder).

  1. mv (move)

Terminal showing mv command moving a file

Let's say we want to move the file.txt from "helloworld" folder to "newfolder", so that helloworld folder has nothing inside, and only the newfolder will have file.txt inside it.
We can do it by typing:

mv ~/Desktop/helloworld/file.txt ~/Desktop/newfolder/
Enter fullscreen mode Exit fullscreen mode

Here too, basically what we are doing is, taking the path of the file.txt i.e. ~/Desktop/helloworld/file.txt (which is inside helloworld folder in desktop) and moving it to where we want to move it, i.e. ~/Desktop/newfolder/ (inside newfolder).

Top comments (2)

Collapse
 
jonrandy profile image
Jon Randy πŸŽ–οΈ

The actual purpose of touch is to update the access date and/or modification date of a file or directory. The fact that it will create a file if it doesn't exist is merely a convenient side effect

Collapse
 
dipsankadariya profile image
Dipsan Kadariya

Hello Jon!! Thank you for your insightful comment. I really appreciate the clarification and have updated my post. Thank you for contributing.