I will going to show you the very basic Linux commands that will important to you in daily basis. (If you are a computer operator who is using linux Opratng System) To be an expert in Linux or anything, first
step for a beginner would be to start learning the basic commands.
Now, let’s look at the basic Linux commands which are most important in Linux. Linux commands are case sensitive , so you need to be careful about what you are typing.
Using man command you can get the user manual of any command that we can run on the terminal. It provides all the details about the command.
ls
list content of the directory. (By default it shows content of the current directory.)
-a Show all content in the directory(including hidden files)
-d List directory entries instead of contents.
-l Show content in the directory as long listing format
-m Show content list as comma separated output
-r Show list in reverse order
-s Show as the allocated size of each file, in blocks.
-S Sort content in the directory by file size
-t Sort content in the directory by last modified
-Q Quoted output (enclose entry names in double quotes)
-1 Show content list in the directory by one file per line
cat
Concatenate files and output. Display content of a file. It can be used to create, view and concatenate files.
#View file $cat filename #View multiple files $cat file1 file2 #Create a file $cat > file #Copy the contents of a file to another file. $cat [filename of the file with content] > destination/[destination filename] #Append the contents of a file to the end of another file. $cat file1 >> file2
pwd
pwd stands for Print Working Directory. pwd command prints the path of the current working directory, starting from the root.
mkdir
mkdir command is used to make directories. Using this command you can create multiple directories at once and you can set the permissions for the directories as well.
-v [verbose] print a message for every created directories. $mkdir -v [directories] -p create parent directories as needed. If parent directories exist, no error will displayed. $mkdir -p [directories] -m This option can be used to set the file mode. File permissions for the created directories. $mkdir -m a=rwx [directories] give access to all users read, write and excecute permissions to content in the created directories. $mkdir -m a=r [directories] give access to all users only read permissions to content in the created directories. $mkdir -m a=w [directories] give access to all users only write permissions to content in the created directories.
rmdir
Used to remove all the directories specified on the command line, if they are empty. Each directory must be empty to execute this command. If the specified directory contain any file or directory it cannot be removed using rmdir.
CP
Copy files and directories from one location to another location. Can be copy one or more files at once.
-b Creates a backup file of the destination file in the same destination directory with different name and different format. -i Interactive coping. ask before overwrite. prompt a warning before overwrite. -n Do not overwrite the existing file. do not overwrite at all (This will overwrite the 'i option' as well)
mv
Move files and directories from one location to another location or rename files and directories. Can be move one or more files at once.
#rename files $mv [filename] [new_filename] #move files -b Creates a backup file of the destination file in the same destination directory with different name and different format. -i Ask before overwrite. prompt a warning before overwrite. -n Do not overwrite the existing file. do not overwrite at all (This will overwrite the 'i option' as well)
chmod
Use to change the access permission of the files and directories. chmod stands for change mode.
There are three permission types of each file and directories according to mode.
- read
- write
- execute
Using this concept you can specify which user can read the file, write to the file or execute the file. This can be done using letter mode as well as numeric mode.
in numeric mode, 4 stand for read , 2 stand for write , 1 stand for execute.
- read ————–> 4
- write ————–> 2
- execute ————–> 1
eg :- rwx – 7 (4+2+1)
change my_file file permission as below.
#user - read, write, execute [7] #group - read, write [6] #other - read, execute [5] $chmod 765 my_file or $chmod u=rwx,g=rw,o=rx my_file
find
Find command used in linux to find files and directories and perform subsequent operation on them. It can be used to search file or directory by name, owner, permission, creation date, modification date and etc. Also it can b used to search file and delete the file with confirmation.
#search a specific file. $find ./[path] -name [name of the file] eg:- $find ./directory_1/directory_2 -name myfile.txt #search files with pattern. $find ./directory_1 -name *.txt #search empty files and directories. $find ./directory_1 -empty #search a file and delete that file with confirmation. $find ./directory_1 -name myfile.txt -exec rm -i {} \; #search a files with specific permission. $find ./directory_1 -perm 766 This will find all the files in the directory_1 (and sub-directories in the directory_1) with the permission 766.
grep
The grep command is use to filter and search file for specific characters, match to given string or word. And it is displaying all the lines containing that pattern.
$grep pattern [file] -c print count of the lines that match the pattern. -i ignore case sensitive. -n print matched lines and their line numbers. -v prints all the lines that do not match the pattern. -w match whole word. -o display only matched segment of the matching line.
You can find Linux command cheat sheet in here, that will really useful in daily basis. (If you are a computer operator who is using Linux Operating System or student or a job seeker in IT field)