DEV Community

Cover image for Basic Linux Commands
Deepak Gupta
Deepak Gupta

Posted on

Basic Linux Commands

File Management Commands: (To list the files and directories stored in the current directory)
The command ls supports the -l and –a option which would help you to get more information about the listed and hidden files ( To enter into a directory)
3.pwd ( to show print working directory)
4.mkdir ( to make a new directory) (to print the content of the file)
6.head ( to print the lines from the top of a file, in default it prints 10 lines can use –n flag to print respective number of lines)
7.tail ( print lines from bottom of a file , similarly –n respective number of lines)
8.touch ( to create a text file)
9.rm (to remove file) and rmdir (to remove a directory)
These commands works when file or directory are empty. But if you want to forcefully remove a directory/file then use command
rm –rf name of directory/file
But be cautious while using this command as it completely delete the object. Preferably it’s not considered to be use.
10.cp ( to copy a file from source destination to a different destination)
cp /home/dee/file1.txt /home/deepak
(Source) (Destination) ( to move a file from source to destination or to rename)
mv /home/dee/file1.txt /home/Deepak
(Source) (Destination)

     mv  /home/dee/file1.txt  /home/Deepak/files.txt
               (Old Name)             (New Name)

File Permissions Command:

Every file in Linux has the following attributes −
• Owner permissions − The owner's permissions determine what actions the owner of the file can perform on the file.
• Group permissions − The group's permissions determine what actions a user, who is a member of the group that a file belongs to, can perform on the file.
• Other (world) permissions − The permissions for others indicate what action all other users can perform on the file.

chmod o+wx testfile (permission given to other’s of write and execute for testfile)
chmod u+rw testfile (permission given to users of read and write for testfile)

The second way to modify permissions with the chmod command is to use a number to specify each set of permissions for the file.

0 || No permission || ---
1 || Execute permission || --x
2 || Write permission || -w-
3 || Execute and write permission: 1(execute)+2(write)=3 || -wx
4 || Read permission || r--
5 || Read and execute permission: 4(read)+1(execute)=5 || r-x
6 || Read and write permission: 4(read)+2(write)=6 || rw-
7 || All permissions: 4(read)+2(write)+1(execute)=7 || rwx

chmod 755 testfile

2.setfacl & getfacl : The command "setfacl" refers to Set File Access Control Lists and "getfacl" refers to Get File Access Control List. Each file and directory in a Linux filesystem is created with a specific set of file permissions for its access. Each user can have different set of file access permissions.

setfacl -m u:deepak:rwx 2.txt ( -m= modify , u=user )

getfacl 2.txt

Processes Management: (easy to see your own processes by running the ps (process status)
Most used flag –f ( f for full) option, which provides more information (command is a very useful tool for quickly showing processes sorted by various criteria).
It is an interactive diagnostic tool that updates frequently and shows information about physical and virtual memory, CPU usage, load averages, and your busy processes.

3.kill (to kill the process running in background)]
$kill 6738 ( 6738 Process ID)
If a process ignores a regular kill command, you can use kill -9 followed by the process ID.

Search Commands (Pipes and Filters)

1.grep (to search for a particular string/word in a text file)

Sr.No. Option & Description
1 -v Prints all lines that do not match pattern.
2 -n Prints the matched line and its line number.
3 -l Prints the names of files with matching lines (letter "l")
4 -c Prints only the count of matching lines.
5 -i Matches either upper or lowercase.

2.find (can be used to find files and directories and perform subsequent operations on them)

find [where to start searching from] [expression determines what to find] [-options] [what to find]

3.locate (used to find the files by name)

Top comments (0)