DEV Community

Elizabeth Onyenekwe
Elizabeth Onyenekwe

Posted on

Basic Linux Commands

Linux Shell Or Terminal

A shell is a program that receives commands from the user and gives it to the OS to process, and it shows the output. Linux's shell is its main part. Its distros come in GUI (graphical user interface), but basically, Linux has a CLI (command line interface). In this article, I am going to cover the basic commands that we use in the shell of Linux.

Basic Linux Commands

pwd: This command shows the current directory that you are in.

~$ pwd
Enter fullscreen mode Exit fullscreen mode

ls: This command lists folders and files.

~$ ls
Enter fullscreen mode Exit fullscreen mode

cd [dirname]: This command opens a folder on the system

~$ cd Documents
Enter fullscreen mode Exit fullscreen mode

mkdir [dirname]: This command creates a folder.

~$ mkdir python-project
Enter fullscreen mode Exit fullscreen mode

touch [filename]: This command creates a file.

~$ touch main.py
Enter fullscreen mode Exit fullscreen mode

rm[filename]: This command deletes a file.

rm main.py
Enter fullscreen mode Exit fullscreen mode

cd..: This command navigates up a directory.

cd..
Enter fullscreen mode Exit fullscreen mode

rm -r [dirname]: This command deletes a folder

~$ rm -r python-project
Enter fullscreen mode Exit fullscreen mode

cd /: This command takes the user to the root folder

cd /
Enter fullscreen mode Exit fullscreen mode

clear: This command clears the terminal

~$ clear
Enter fullscreen mode Exit fullscreen mode

cd [dirname]/[dirname]/[dirname]: This command lets you navigate down the directories to a particular folder.

~$ cd usr/local/bin
Enter fullscreen mode Exit fullscreen mode

cd ../..: This command moves two hierarchies up the file system

cd ../..
Enter fullscreen mode Exit fullscreen mode

cd ~: This command takes the user back to the home directory

cd ~
Enter fullscreen mode Exit fullscreen mode

ls /[dirname]/[dirname]: This command lists all the files in the directory name after navigating to that particular directory.

ls /etc/network
Enter fullscreen mode Exit fullscreen mode

mv[dirname][new-dirname]: This changes the folder name

mv web-application java-app
Enter fullscreen mode Exit fullscreen mode

cp -r [dirname][new-dirname]: This copies the content of a particular folder into another folder.

cp -r java-app my-project
Enter fullscreen mode Exit fullscreen mode

cp [filename][new-filename]: This copies the content of a file into another file.

cp readme.md readme-test.md
Enter fullscreen mode Exit fullscreen mode

mv[filename][filename]: This changes the filename

mv readme.md readme-dev.md
Enter fullscreen mode Exit fullscreen mode

ls -r [dirname]: This shows the entire content of that directory.

ls -r Documents
Enter fullscreen mode Exit fullscreen mode

history: Gives a history of all past commands typed in the current terminal session

~$ history
Enter fullscreen mode Exit fullscreen mode

ctrl + r: This key combination searches for the history of a command a user recently used.

ctrl + c: This key combination stops the current command that is running.

history[number]: This shows the last set of commands that were typed. The last set is determined by the number the user inputs.

history 20
Enter fullscreen mode Exit fullscreen mode

ls -a: It shows all files including hidden files

ls -a
Enter fullscreen mode Exit fullscreen mode

cat[filename]: This displays the file content

cat main.py
Enter fullscreen mode Exit fullscreen mode

uname -a: This displays the system information and the kernel

~$ uname -a
Enter fullscreen mode Exit fullscreen mode

cat /etc/os-release: This shows the version of your operating system

~$ cat /etc/os-release
Enter fullscreen mode Exit fullscreen mode

lscpu: This shows the cpu information

~$ lscpu
Enter fullscreen mode Exit fullscreen mode

lsmem: This displays the memory information

~$ lsmem 
Enter fullscreen mode Exit fullscreen mode

References

  1. Basic linux commands for beginners by Alok Naushad " https://maker.pro/linux/tutorial/basic-linux-commands-for-beginners "
  2. Techworld with Nana Devops Bootcamp

Top comments (0)