34 Basic Linux Commands with Syntax Part-II
Job-ready Online Courses: Click, Learn, Succeed, Start Now!
1. Basic Linux Commands
This is the basic Linux commands tutorial tutorial, contain Linus commands lists, which are useful for beginners while getting familiar with Linux.
So, let’s start Basic Linux Commands Tutorial.
2. Basic Linux Commands List
Top 34 basic Linux commands are given below In this section of Important Linux Commands Tutorial along with their usage-
2.1. gzip
a. Usage:
$ gzip filename
It compresses content of files, gives extension of .gz and needs to be uncompressed before use.
2.2. touch
a. Usage:
$ touch filename
It creates new empty file. It is another way to create a file. It is also used to change date and time of most recent access and modification.
2.3. locate
Usage:
$ locate filename
Technology is evolving rapidly!
Stay updated with DataFlair on WhatsApp!!
It is used to search find files by its name. It searches extremely fast, runs in background to trace the location of files. locate command is fast because it runs in background process in a system. It searches the file and stores them in a database.
2.4. echo
Usage:
$ echo String
It writes arguments to the standard output or display line of text. It is mostly used in batch and scripts. It plays an important role in building shell script.
2.5. grep
a. Usage:
$ grep “String” filename
It mainly searches the text or searches the file for lines containing a match to the given strings or words. It searches the mention string in given file.
b. Usage:
$ grep "String" filename1 filename2
It searches the mentioned String in multiple files mentioned.
2.6. clear
Usage:
$ clear
It clears the screen which is equivalent to ctrl+L while using keyboard. It looks in the environment for terminal type and then in the terminal database to figure out how to clear the screen.
2.7. logout
Usage:
$ logout
To exit a login shell or to get out from current session. It can be used by any normal user to end their session.
2.8. exit
Usage:
$ exit
To exit a shell like log out. It will remind that some jobs are running in background and again writing exit will terminate them and finally it will close the shell.
2.9. wc
a. Usage:
$ wc [options] filename
Prints the number of newlines, word, bytes in a file. It is used to find out the number of newline count, word count, byte and characters count in files.
b. Usage:
$ wc -l filename
Prints the number of lines in a file.
c. Usage:
$ wc -w filename
Prints the number of words in a file.
d. Usage:
$ wc -c filename
Display the count of bytes of file.
2.10. sort
a. Usage:
$ sort filename
Simply sorts the file in alphabetical order. It is used for printing lines of input text files and concatenation of all files in sorted order. It takes blank space like field separator .entire input file like sort key. It is important to know that sort command don’t actually sort the files but only print the sorted output.
b. Usage:
$ sort -u filename
-u removes duplicate records in a file and only first record is retained.
c. Usage:
$ sort -n file
It sorts a file numerically.
2.11. kill
Usage:
$ kill
It stops a process. It kills or terminates a process without logging out or restarting the system. It sends signal to each process specified by process identifier.
2.12. ps
a. Usage:
$ ps
It will display current running process in system. It is also used for view process running on system. It provides an information of current process with detailed information like CPU usage, user id, command name and memory usage.
b. Usage:
$ ps -ax
It shows all current running process.
2.13. uptime
Usage:
$ uptime
It shows how long system has been running. It will show current time of system, how many users are currently active and system load average
2.14. sleep
a. Usage:
$ sleep number [suffix]
Delay or pause for specified amount of time. It actually causes the system with given amount of time. It suspends the system for mentioned duration then turns on or resume after the duration gets over.
b. Usage:
$ sleep (n)
Sleeps for (n) seconds.
c. Usage:
$ sleep (nm)
Sleeps for (n) minutes.
d. Usage:
$ sleep (nh)
Sleeps for (n) hours.
e. Usage:
$ sleep (nd)
Sleeps for (n) days.
2.15. seq
a. Usage:
$ seq n
Prints number starting from 1 to n. It prints the numbers from first to last with an increment. By default, first and increment are both 1, and each number is printed on its own line. All numbers can be real, not just integers.
b. Usage:
$ seq n1 n2
Prints number starting from n1 to n2.
2.16. cut
a. Usage:
$ cut c(n) filename
Print characters in a line by specifying the position of the characters.
b. Usage:
$ cut -c(n), (n) file.txt
To print more than one character at a time by specifying the character positions in a comma separated list.
2.17. paste
a. Usage:
$ paste filename
Print the content of file. The paste command merges the lines from multiple files.This is a useful tool for merging a single file and also set of files. The paste command sequentially writes the corresponding lines from each file separated by a delimiter on terminal.
b. Usage:
$ paste filename1 filename2
Prints the content of file1 and file2 side by side.
2.18. cal
Usage:
$ cal
Displays a calendar. cal displays a simple calendar. If no arguments are mentioned, the current month is displayed on screen.
2.19. uniq
a. Usage:
$ unique filename
It removes duplicate lines in a file and display unique contents. uniq reports or filters out repeated lines in a mentioned file. It suppress the duplicate lines from a file. It discards all the successive similar lines except one from the input and writes the output.
b. Usage:
$ uniq -c filename
It counts occurrence of lines in a file.
c. Usage:
$ uniq -dfilename
It prints only duplicate repeated lines.
2.20. du
a. Usage:
$ du
Display and estimate disk usage in current directory. It is used to show Linux directory size or to know how large subdirectories are, including all the files and subdirectories it contains.
b. Usage:
$ du -a
Display and estimate disk usage of all file in current directory.
c. Usage:
$ du -h
Display result in human readable format like in kilobytes, megabytes.
2.21. find
a. Usage:
$ find
List files in current and subdirectories. It is a very useful and easy handy command to search for files from the command line. It can be used to find files based on various search conditions like permissions, user ownership, modification date/time, size etc.
b. Usage:
$ find ./directory name
Searches all the files in mentioned directory.
2.22. diff
a. Usage:
$ diff filename 1 filename2
It displays the difference between two files, best way to find discrepancies b/w files which feels like they are same. It analyzes two files and prints the lines that are different. It gives output as a set of instructions for how to change one file in order to make it identical to the second file.
2.23. join
Usage:
$ join filename1 filename2
Join two files based on matching or common field of data. Those who know SQL Join it is similar to like that. It combines two files based on the matching content lines found in each file. Using this Linux command is quite easy and if used currently and in the right situation it can save lots of time and effort.
2.24. split
a. Usage:
$ split -l filename
Split the file based on the number of lines and then makes a new file of partitioned content where file name will always start with x. It is used to split a file into two or more smaller files; default behaviour of split is to generate output files of a fixed size, default 1000 lines.
b. Usage:
$ split -b filename
Specify the number of bytes that each partitioned file should contains.
2.25. hostname
Usage:
$ hostname
Prints the hostname, like computer name. It is used to display the system’s Domain Name System or Service or Server name, and to display or set its hostname or Network Information Services domain name.
2.26. rev
Usage:
$ rev String
It reverses the given string. It reverses the order of characters in every line; it copies the specified files to the standard output, reversing the order of each character in every line. If no files are mentioned, the standard input is read.
2.27. tar
Usage:
$ tar -czvf archivename.tar.gz /path/to/directory or file
a.Compress an entire directory or a Single File where :
c: Creates an archive.
-z: Compresses the archive with gzip.
-v: Display progress in the terminal while creating the archive. v is always optional in these Linux commands.
f: Allows you to specify the filename of the archive.
b. Usage:
$ tar -xzvf archive.tar.gz
To extract an archive,where:
x – extract files from archive.
2.28. sudo apt –get install
a: Usage:
$ sudo apt-get install
apt-get is the command-line tool for working with APT software packages which will install one or more packages desired for installation.
b. Usage:
$ sudo apt-get update
It will download the package list from the repositories, updates them to get information on the newest versions of packages and their dependencies.
c. Usage:
$ sudo apt-get upgrade
It is used to upgrade all the currently installed software packages on the system.
2.29. which
Usage:
$ which filename
It shows path of Linux command in your path. It takes one or more arguments where for each of its arguments it prints the full path of the executable. It returns the pathname of the files or link which would be executed in the current environment.
2.30. version
Usage:
$ filename -version
This Linux command is used to print out version information about OpenSSL (Secure Sockets Layer)or prints OpenSSL version information.
2.31. top
Usage:
$ top
It displays top CPU process. It provides a current progress look at processor activity in real time. It can sort the tasks by CPU usage, memory usage and runtime. It displays a listing of the most CPU-intensive tasks on the system, and provides an interactive interface for manipulating processes.
2.32. who
Usage:
$ who
Display who logged on along with time for current session. It is used to print information about users who are currently active in. It can only see a real user who logged in. It won’t see a user who is online with su command (switch user).
2.33. tail
a. Usage:
$ tail filename
It displays last 10 lines of mentioned file. It is used to print the last N lines from the file on the terminal. It used with log files to read the last few lines to know about the error messages.
b. Usage:
$ tail filename -n 1000
It outputs the last 100 lines of the filename.
2.34. head
a. Usage:
$ head filename
Prints first 10 numbers of lines from the mentioned file.
b.Usage:
head -n myfile.txt
Display the first n lines of mentioned file. If more than one file is mentioned, head will show the first ten lines of each file individually.
So, this was all about Basic Linux Commands. Hope you like our explanation.
Furthermore, if you have any query, feel free to ask in the comment box.
Did you like our efforts? If Yes, please give DataFlair 5 Stars on Google
Very useful information.
Is it required to learn all linux commands??