What is Linux?
Linux is an Operating System’s Kernel. You might have heard of UNIX. Well, Linux is a UNIX clone. But it was actually created by Linus Torvalds from Scratch. Linux is free and open-source, that means that you can simply change anything in Linux and redistribute it in your own name! There are several Linux Distributions, commonly called “distros”. A few of them are:
- Ubuntu Linux
- Red Hat Enterprise Linux
- Linux Mint
- Debian
- Fedora
Linux is Mainly used in Servers. About 90% of the Internet is powered by Linux Servers. This is because Linux is fast, secure, and free! The main problem of using Windows Servers are their cost. This is solved by using Linux Servers. Forgot to mention, the OS that runs in about 80% of the Smartphones in the World, Android, is also made from the Linux Kernel. Yes, Linux is amazing! A simple example of its security is that most of the viruses in the world run on Windows, but not on Linux!
Linux Shell or “Terminal”
So, basically, 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 tutorial, we are going to cover the Basic Commands that we use in the Shell of Linux.
We can open the terminal by Ctrl+Alt+T in Ubuntu, or by pressing Alt+F2 and then typing in gnome-terminal and press Enter. In raspberry Pi, it is lxterminal that we should type in. There is also a GUI way of taking it, but this is better!
Linux Commands
Basic Commands
1. pwd
When you first open the terminal, you are in the home directory of your user. To know which directory you are in, you can use the “pwd” command. It gives us the Absolute Path, which means the path that starts from the root. The root is the base of the Linux filesystem. It is denoted by a forward slash( / ). The user directory is usually something like /home/username.
2. ls
The “Is” command is used to know what files are there in the directory you are in. You can see all the hidden files by using the command “ls -a”.
3. cd
“cd” is the command used to go to a directory. For example, if you are in the home folder, and you want to go to the Downloads folder, then you can type in “cd Downloads”. Remember, this command is case sensitive and you have to type in the name of the folder exactly as it is. But there is a problem with these commands. Imagine you have a folder named “Raspberry Pi”. In this case, when you type in “cd Raspberry Pi”, the shell will take the second argument of the command as a different one, so you will get an error saying that the directory does not exist. Here, you can use a backward slash. That is, you can use “cd Raspberry\ Pi” in this case. Spaces are denoted like this: If you just type “cd” and press Enter, it takes you to the home directory. To go back from a folder to the folder before that, you can type “cd ..” . The two dots represent back.
4. mkdir & rmdir
The mkdir command is used when you need to create a folder or a directory. For Example, if you want to make a directory called “DIY”, then you can type “mkdir DIY”. Remember, as told before, if you want to create a directory named “DIY Hacking”, then you can type “mkdir DIY\ Hacking”.
rmdir is the command used for deleting a directory. But, rmdir can only be used to delete an empty directory. To delete a directory containing files, rm is used.
5. rm
The rm command is used to delete files and directories. rm cannot simply delete a directory. “rm -r” is used to delete a directory. In this case, it deletes both the folder and the files in it.
6. touch
The touch command is used to create a file. It can be anything, from an empty txt file to an empty zip file. For example – “touch new.txt”
7. man & –help
To know more about a command and on how to use it, the man command is used. It shows the manual pages of the command. For Example, “man cd” shows the manual pages of the cd command. Typing in the command name and the argument helps it show which ways the command can be used (Example – cd –help).
8. cp
The cp command is used to copy files through the command line. It takes two arguments, the first one is location of the file to be copied, the second iswhere to copy.
9. mv
The mv command is used to move files through the command line. We can also use the mv command to rename a file. For example, if we want to rename the file “text” to “new”, we can use “mv text new”. It takes the two arguments just like the cp command.
10. locate
The locate command is used to locate a file in a Linux System, just like the search command in Windows. This command is useful when you don’t know where a file is saved or the actual name of the file. Using the –i argument with the command, helps to ignore the case (it doesn’t matter if it is Capital or Small). So, if you want a file that has the word “hello”, it gives the list of all the files in your Linux System containing the word “hello” when you type in “locate -i hello”. If you remember two words, you can separate it using asterisk (*). For example, to locate a file containing the words “hello” and “this”, you can use the command “locate –i *hello*this ”
Intermediate Commands
1. echo
“echo” is a command that helps us move some data, usually text into a file. For example, if you want to create a new text file or add into an already made text file, then you just need to type in “echo hello, my name is alok >> new.txt”. You do not need to separate the spaces by using the backward slash here because we put in two triangular brackets when we finish what we need to write.
2. cat
The cat command is used to display the contents of a file, usually used to easily view programs.
3. nano, vi, jed
nano and vi are already installed text editors in the Linux command line. nano is a good text editor which denotes keywords with color and can recognize most of the languages. Vi is simpler than nano. You can create a new file or modify one using this editor. For example, if you need to make a new file named “check.txt”, you can create it by using the command “nano check.txt”. You can save your files after editing by using the sequence, Ctrl+X, then Y (or N for no). In my experience, using nano for HTML editing doesn’t seem so good, because of its color, so I recommend jed text editor. We will come to installing packages soon.
4. sudo
sudo is a widely used command in the Linux command line. sudo stands for “SuperUser Do”. So, if we want any command to be done with administrative or root privileges, then you can use the sudo command. For Example, if you want to edit a file like viz. alsa-base.conf which needs root permissions, you can use the command – sudo nano alsa-base.conf . You can enter the root command line using the command “sudo bash”, then type in your user password. You can also use the command “su” to do this, but you need to set a root password before that. For that, you can use the command “sudo passwd”(it wasn’t misspelled, it is passwd). Then type in the new root password.
5. df
The df command is used to see the available disk space in each of the partitions in your system. You can just type in df in the command line and you can see each mounted partition and their used/available space in % and in KBs. If you want it shown in megabytes, you can use the command “df -m”
6. du
du is a command to know the disk usage of a file in your System. If you want to know the disk usage for a particular folder or file in Linux, then you can type in the command df and the name of the folder or file. For example, if you want to know the disk space used by the folder Documents in Linux, you can use the command “du Documents”. You can also use the command “ls -lah” to view the file sizes of all the files in a folder.
7. tar
tar is a command used to work with tarballs (or files compressed in a tarball archive) in the Linux Command Line. It has a long list of uses. It can be used to compress and uncompress different types of tar archives like .tar, .tar.gz, .tar.bz2.etc. It works on the basis of the arguments given to it. For example, tar -cvf for creating a .tar archive, -xvf to untar a tar archive, -tvf to list the contents of the archive.etc. As it is a wide topic, here are some examples of tar commands.
8. zip, unzip
zip is a command used to compress files into a zip archive, unzip is used to extract files from a zip archive.
9. uname
uname is a command used to show the Information about the system your Linux distro is running. Using the command “uname -a” prints most of the information about the system. This prints the Kernel release date, version, processor type. etc.
10. apt-get
apt is a command used to work with packages in the Linux command line. apt-get is a command used to install packages. This requires root privileges, so we use the sudo command with it. For example, if we want to install the text editor jed (as I mentioned earlier), we can type in the command “sudo apt-get install jed”. Similarly, any packages can be installed like this. It is good to update your repository each time you try to install a new package. You can do that by typing “sudo apt-get update”. You can upgrade the system by typing “sudo apt-get upgrade”. We can also upgrade the distro by typing “sudo apt-get dist-upgrade”. The command “apt-cache search” is used to search for a package. If you want to search for one, you can type in “apt-cache search jed”(This doesn’t require root).
11. chmod
chmod is the command used to make a file executable and to change the permissions granted to it in Linux. Imagine you have a python code named numbers.py in your computer, you’ll need to run “python numbers.py” every time you need to run it. Instead of that, when you make it executable, you’ll just need to run “numbers.py” in the terminal to run the file. To make a file executable, you can use the command “chmod +x numbers.py” in this case. You can use “chmod 755 numbers.py” to give it root permissions or “sudo chmod +x numbers.py” for root executable. Here is some more information about the chmod command.
12. hostname
hostname is a command used to know your name in your host or your network. Basically, it displays your hostname and IP address. Typing just “hostname” gives the output, your hostname. Typing in “hostname -I” gives you your IP address in your network.
13. ping
ping is a command used to check your connection to a server. Wikipedia says that “Ping is a computer network administration software utility used to test the reachability of a host on an Internet Protocol (IP) network”. Simply, when you type in, for example, “ping google.com”, it checks if it can connect to the server and come back. It measures this round-trip time and gives you the details about it. The use of this command for simple users like us is to check your internet connection. If it pings the Google server (in this case), you can confirm that your internet connection is active!
Tips and Tricks in Using Linux Command Line
- You can use clear command to clear the terminal if it gets filled up with too many commands!
- TAB can be used to fill up in Terminal. For example, You just need to type “cd Doc” and then TAB and the terminal fills the rest up and makes it “cd Documents”.
- Ctrl+C can be used to stop any command in terminal safely. If it doesn’t stop with that, then Ctrl+Z can be used to force stop it.
- You can exit from the terminal by using the exit command.
- You can power off or reboot the computer by using the command sudo halt and sudo reboot.
Important Linux Commands
This section gives insight into the most important commands of your SuSE Linux system. Along with the individual commands, parameters are listed and, where appropriate, a typical sample application is introduced. To learn more about the various commands, it is usually possible to get additional information with the man program followed by the name of the command, for example, man ls.
In these manual pages, move up and down with PgUp and PgDn and move between the beginning and the end of a document with Home and End. End this viewing mode by pressing Q. Learn more about the man command itself with man.
There are many more commands than listed in this chapter. For information about other commands or more detailed information, we recommend the O'Reilly publication Linux in a Nutshell. In the following overview, the individual command elements are written in different typefaces.
- The actual command is always printed as command. Without this, nothing can function.
- Options without which the respective program cannot function are printed in italics.
- Further details, like file names, which must be passed to a command for correct functioning, are written in the Courier font.
- Specifications or parameters that are not required are placed in [brackets].
Adjust possible specifications to your needs. It makes no sense to write ls file(s), if no file named file(s) actually exists. You can usually combine several parameters, for example, by writing ls -la instead of ls -l -a.
- ls [option(s)] [file(s)]
If you run ls without any additional parameters, the program will list the contents of the current directory in short form.- -l
- detailed list
- -a
- displays hidden files
- cp [option(s)] sourcefile targetfile
Copies sourcefile to targetfile.- -i
- Waits for confirmation, if necessary, before an existing targetfile is overwritten
- -r
- Copies recursively (includes subdirectories)
- mv [option(s)] sourcefile targetfile
Copies sourcefile to targetfile then deletes the original sourcefile.- -b
- Creates a backup copy of the sourcefile before moving
- -i
- Waits for confirmation, if necessary, before an existing targetfile is overwritten
- rm [option(s)] file(s)
Removes the specified files from the file system. Directories are not removed by rm unless the option -r is used.- -r
- Deletes any existing subdirectories
- -i
- Waits for confirmation before deleting each file.
- ln [option(s)] sourcefile targetfile
Creates an internal link from the sourcefile to the targetfile, under a different name. Normally, such a link points directly to the sourcefile on one and the same file system. However, if ln is executed with the -s option, it creates a symbolic link that only points to the directory where the sourcefile is located, thus enabling linking across file systems.- -s
- Creates a symbolic link
- cd [options(s)] [directory]
Changes the current directory. cd without any parameters changes to the user's home directory.- mkdir [option(s)] directoryname
Creates a new directory.- rmdir [option(s)] directoryname
Deletes the specified directory, provided it is already empty.- chown [option(s)] username.group file(s)
Transfers the ownership of a file to the user with the specified user name.- -R
- Changes files and directories in all subdirectories.
- chgrp [option(s)] groupname file(s)
Transfers the group ownership of a given file to the group with the specified group name. The file owner can only change group ownership if a member of both the existing and the new group.- chmod [options] mode file(s)
Changes the access permissions.The mode parameter has three parts: group, access, and access type. group accepts the following characters:- u
- user
- g
- group
- o
- others
For access, access is granted by the + symbol and denied by the - symbol.The access type is controlled by the following options:- r
- read
- w
- write
- x
- eXecute — executing files or changing to the directory.
- s
- Set uid bit — the application or program is started as if it were started by the owner of the file.
- gzip [parameters] file(s)
This program compresses the contents of files, using complex mathematical algorithms. Files compressed in this way are given the extension .gz and need to be uncompressed before they can be used. To compress several files or even entire directories, use the tar command.- -d
- decompresses the packed gzip files so they return to their original size and can be processed normally (like the command gunzip).
- tar options archive file(s)
The tar puts one file or (usually) several files into an archive. Compression is optional.tar is a quite complex command with a number of options available. The most frequently used options are:- -f
- Writes the output to a file and not to the screen as is usually the case
- -c
- Creates a new tar archive
- -r
- Adds files to an existing archive
- -t
- Outputs the contents of an archive
- -u
- Adds files, but only if they are newer than the files already contained in the archive
- -x
- Unpacks files from an archive (extraction)
- -z
- Packs the resulting archive with gzip
- -j
- Compresses the resulting archive with bzip2
- -v
- Lists files processed
The archive files created by tar end with .tar. If the tar archive was also compressed using gzip, the ending is .tgz or .tar.gz. If it was compressed using bzip2, .tar.bz2.Application examples can be found in Section “Archives and Data Compression”.- locate pattern(s)
The locate command can find in which directory a specified file is located. If desired, use wild cards to specify file names. The program is very speedy, as it uses a database specifically created for the purpose (rather than searching through the entire file system). This very fact, however, also results in a major drawback: locate is unable to find any files created after the latest update of its database.The database can be generated by root with updatedb.- updatedb [options(s)]
This command performs an update of the database used by locate. To include files in all existing directories, run the program as root. It also makes sense to place it in the background by appending an ampersand (&), so you can immediately continue working on the same command line (updatedb &).- find [option(s)]
The find command allows you to search for a file in a given directory. The first argument specifies the directory in which to start the search. The option -name must be followed by a search string, which may also include wild cards. Unlike locate, which uses a database, find scans the actual directory.
- cat [option(s)] file(s)
The cat command displays the contents of a file, printing the entire contents to the screen without interruption.- -n
- Numbers the output on the left margin
- less [option(s)] file(s)
This command can be used to browse the contents of the specified file. Scroll half a screen page up or down with PgUp and PgDn or a full screen page down with Space. Jump to the beginning or end of a file using Home and End. Press Q to exit the program.- grep [option(s)] searchstring filenames
The grep command finds a specific searchstring in the specified file(s). If the search string is found, the command displays the line in which the searchstring was found along with the file name.- -i
- Ignores case
- -l
- Only displays the names of the respective files, but not the text lines
- -n
- Additionally displays the numbers of the lines in which it found a hit
- -l
- Only lists the files in which searchstring does not occur
- diff [option(s)] file1 file2
The diff command compares the contents of any two files. The output produced by the program lists all lines that do not match.This is frequently used by programmers who need only send their program alterations and not the entire source code.- -q
- Only reports whether the two given files differ
- mount [option(s)] [<device>] mountpoint
This command can be used to mount any data media, such as hard disks, CD-ROM drives, and other drives, to a directory of the Linux file system.- -r
- mount read-only
- -t filesystem
- Specifies the file system. The most common are ext2 for Linux hard disks, msdos for MS-DOS media, vfat for the Windows file system, and iso9660 for CDs.
For hard disks not defined in the file /etc/fstab, the device type must also be specified. In this case, only root can mount. If the file system should also be mounted by other users, enter the option user in the appropriate line in the /etc/fstab file (separated by commas) and save this change. Further information is available in mount.- umount [option(s)] mountpoint
This command unmounts a mounted drive from the file system. To prevent data loss, run this command before taking a removable data medium from its drive. Normally, only root is allowed to run the commands mount and umount. To enable other users to run these commands, edit the /etc/fstab file to specify the option user for the respective drive.
- df [option(s)] [directory]
The df (disk free) command, when used without any options, displays information about the total disk space, the disk space currently in use, and the free space on all the mounted drives. If a directory is specified, the information is limited to the drive on which that directory is located.- -H
- shows the number of occupied blocks in gigabytes, megabytes, or kilobytes — in human-readable format
- -t
- Type of file system (ext2, nfs, etc.)
- du [option(s)] [path]
This command, when executed without any parameters, shows the total disk space occupied by files and subdirectories in the current directory.- -a
- Displays the size of each individual file
- -h
- Output in human-readable form
- -s
- Displays only the calculated total size
- free [option(s)]
The command free displays information about RAM and swap space usage, showing the total and the used amount in both categories.- -b
- Output in bytes
- -k
- Output in kilobytes
- -m
- Output in megabytes
- date [option(s)]
This simple program displays the current system time. If run as root, it can also be used to change the system time. Details about the program are available in date.
- top [options(s)]
top provides a quick overview of the currently running processes. Press H to access a page that briefly explains the main options to customize the program.- ps [option(s)] [process ID]
- If run without any options, this command displays a table of all your own programs or processes — those you started. The options for this command are not preceded by hyphen.
- aux
- Displays a detailed list of all processes, independent of the owner.
- kill [option(s)] process ID
Unfortunately, sometimes a program cannot be terminated in the normal way. However, in most cases, you should still be able to stop such a runaway program by executing the kill command, specifying the respective process ID (see top and ps).kill sends a TERM signal that instructs the program to shut itself down. If this does not help, the following parameter can be used:- -9
- Sends a KILL signal instead of a TERM signal, with which the process really is annihilated by the operating system. This brings the specific processes to an end in almost all cases.
- killall [option(s)] processname
This command is similar to kill, but uses the process name (instead of the process ID) as an argument, causing all processes with that name to be killed.
- ping [option(s)] host name|IP address
The ping command is the standard tool for testing the basic functionality of TCP/IP networks. It sends a small data packet to the destination host, requesting an immediate reply. If this works, ping displays a message to that effect, which indicates that the network link is basically functioning.- -c
- number Determines the total number of packages to send and ends after they have been dispatched. By default, there is no limitation set.
- -f
- flood ping: sends as many data packages as possible. A popular means, reserved to root, to test networks.
- -i
- value Specifies the interval between two data packages in seconds. Default: one second
- nslookup
The Domain Name System resolves domain names to IP addresses. With this tool, send queries to information servers (DNS servers).- telnet [option(s)] host name or IP address
- Telnet is actually an Internet protocol that enables you to work on remote hosts across a network. telnet is also the name of a Linux program that uses this protocol to enable operations on remote computers.
Warning
Do not use telnet over a network on which third parties can eavesdrop. Particularly on the Internet, use encrypted transfer methods, such as ssh, to avoid the risk of malicious misuse of a password (see the man page for ssh).
- passwd [option(s)] [username]
Users may change their own passwords at any time using this command. Furthermore, the administrator root can use the command to change the password of any user on the system.- su [option(s)] [username]
The su command makes it possible to log in under a different user name from a running session. When using the command without specifying a user name, you will be prompted for the root password. Specify a user name and the corresponding password to use the environment of the respective user. The password is not required from root, as root is authorized to assume the identity of any user.- halt [option(s)]
- To avoid loss of data, you should always use this program to shut down your system.
- reboot [option(s)]
Does the same as halt with the difference that the system performs an immediate reboot.- clear
This command cleans up the visible area of the console. It has no options.The vi Editor
Operating the vi editor takes some practice. For many, it is the preferred editor, partly because it is available on any UNIX-like operating system and is included in default Linux installations. Also, if nothing else works, vi will. The short instructions that follow should enable you to edit various configuration files and other types of files with vi.vi provides three operating modes. In command mode keys are interpreted as command elements. Insert mode interprets all keys as text entries and last line mode is used for more complex commands, which are entered in the last line.The most important commands in command mode are:
Table 24.1. Simple Commands of the vi EditorESC Changes to last line mode. i Changes to insert mode (characters appear at the current cursor position). a Changes to insert mode (characters appear after the current cursor position). A Changes to insert mode (characters are added at the end of the line). R Changes to command mode (overwrites the old text). r Changes to insert mode and overwrites each character. s Changes to insert mode (the character where the cursor is positioned is replaced by the next entry you make). C Changes to insert mode (the rest of the line is replaced by the new text). o Changes to insert mode (a new line is inserted following the current one). O Changes to insert mode (a new line is inserted preceding the current one). x Deletes the current character. dd Deletes the current line. dw Deletes up to the end of the current word. cw Changes to insert mode (the rest of the current word is overwritten by the next entries you make). u Undoes the last command. J Joins the following line with the current one. . Repeats the last command. : Changes to last line mode. Each command can be preceded by a number specifying on how many objects the following command should operate. Delete three words at once by entering 3dw. The command 10x deletes ten characters after the cursor position and 20dd deletes twenty lines.The most important commands in last line mode are:- There are a countless number of commands in Linux. We are bound to use a number of them on a daily routine or numerous times to perform common tasks than others. It is important to note that certain commands are “distro-based” – they can only be found in specific distros. While others are generic Unix/Linux commands that you’ll find in all if not most mainstream distros.In this article, we will introduce you a list of most frequently used Linux commands with their examples for easy learning. You can find the actual description of each Linux command in their manual page which you can access like this:
adduser/addgroup Command
The adduser and addgroup commands are used to add a user and group to the system respectively according to the default configuration specified in /etc/adduser.conf file.agetty Commandagetty is a program which manages physical or virtual terminals and is invoked by init. Once it detects a connection, it opens a tty port, asks for a user’s login name and calls up the /bin/login command. Agetty is a substitute of Linux getty:alias Command
alias is a useful shell built-in command for creating aliases (shortcut) to a Linux command on a system. It is helpful for creating new/custom commands from existing Shell/Linux commands (including options):The above command will create an alias called home for /home/tecmint/public_html directory, so whenever you type home in the terminal prompt, it will put you in the /home/tecmint/public_html directory.anacron Command
anacron is a Linux facility used to run commands periodically with a frequency defined in days, weeks and months.Unlike its sister cron; it assumes that a system will not run continuously, therefore if a scheduled job is due when the system is off, it’s run once the machine is powered on.apropos Command
apropos command is used to search and display a short man page description of a command/program as follows.apt Command
apt tool is a relatively new higher-level package manager for Debian/Ubuntu systems:apt-get Commandapt-get is a powerful and free front-end package manager for Debian/Ubuntu systems. It is used to install new software packages, remove available software packages, upgrade existing software packages as well as upgrade entire operating system.aptitude Commandaptitude is a powerful text-based interface to the Debian GNU/Linux package management system. Like apt-get and apt; it can be used to install, remove or upgrade software packages on a system.arch Commandarch is a simple command for displaying machine architecture or hardware name (similar to uname -m):arp Command
ARP (Address Resolution Protocol) is a protocol that maps IP network addresses of a network neighbor with the hardware (MAC) addresses in an IPv4 network.You can use it as below to find all alive hosts on a network:at Command
at command is used to schedule tasks to run in a future time. It’s an alternative to cron and anacron, however, it runs a task once at a given future time without editing any config files:For example, to shutdown the system at 23:55 today, run:atq Command
atq command is used to view jobs in at command queue:atrm Command
atrm command is used to remove/deletes jobs (identified by their job number) from at command queue:awk CommandAwk is a powerful programming language created for text processing and generally used as a data extraction and reporting tool.batch Commandbatch is also used to schedule tasks to run a future time, similar to the at command.basename Command
basename command helps to print the name of a file stripping of directories in the absolute path:bc Command
bc is a simple yet powerful and arbitrary precision CLI calculator language which can be used like this:bg Command
bg is a command used to send a process to the background.bzip2 Commandbzip2 command is used to compress or decompress file(s).cal CommandThe cal command print a calendar on the standard output.cat Command
cat command is used to view contents of a file or concatenate files, or data provided on standard input, and display it on the standard output.chgrp Command
chgrp command is used to change the group ownership of a file. Provide the new group name as its first argument and the name of file as the second argument like this:chmod Command
chmod command is used to change/update file access permissions like this.chown Command
chown command changes/updates the user and group ownership of a file/directory like this.cksum Commandcksum command is used to display the CRC checksum and byte count of an input file.clear Command
clear command lets you clear the terminal screen, simply type.cmp Command
cmp performs a byte-by-byte comparison of two files like this.comm Command
comm command is used to compare two sorted files line-by-line as shown below.cp Command
cp command is used for copying files and directories from one location to another.date Command
date command displays/sets the system date and time like this.dd Command
dd command is used for copying files, converting and formatting according to flags provided on the command line. It can strip headers, extracting parts of binary files and so on.The example below shows creating a boot-able USB device:df Command
df command is used to show file system disk space usage as follows.diff Commanddiff command is used to compare two files line by line. It can also be used to find the difference between two directories in Linux like this:dir Commanddir command works like Linux ls command, it lists the contents of a directory.dmidecode Command
dmidecode command is a tool for retrieving hardware information of any Linux system. It dumps a computer’s DMI (a.k.a SMBIOS) table contents in a human-readable format for easy retrieval.To view your system hardware info, you can type:du Commanddu command is used to show disk space usage of files present in a directory as well as its sub-directories as follows.echo Command
echo command prints a text of line provided to it.eject Command
eject command is used to eject removable media such as DVD/CD ROM or floppy disk from the system.env Command
env command lists all the current environment variables and used to set them as well.exit Commandexit command is used to exit a shell like so.expr Command
expr command is used to calculate an expression as shown below.factor Command
factor command is used to show the prime factors of a number.find Command
find command lets you search for files in a directory as well as its sub-directories. It searches for files by attributes such as permissions, users, groups, file type, date, size and other possible criteria.free Command
free command shows the system memory usage (free, used, swapped, cached, etc.) in the system including swap space. Use the-h
option to display output in human friendly format.grep Command
grep command searches for a specified pattern in a file (or files) and displays in output lines containing that pattern as follows.groups Command
groups command displays all the names of groups a user is a part of like this.gzip Command
Gzip helps to compress a file, replaces it with one having a.gz
extension as shown below:gunzip Command
gunzip expands or restores files compressed with gzip command like this.head Command
head command is used to show first lines (10 lines by default) of the specified file or stdin to the screen:history Command
history command is used to show previously used commands or to get info about command executed by a user.hostname Command
hostname command is used to print or set system hostname in Linux.hostnamectl Command
hostnamectl command controls the system hostname under systemd. It is used to print or modify the system hostname and any related settings:hwclock
hwclock is a tool for managing the system hardware clock; read or set the hardware clock (RTC).hwinfo Command
hwinfo is used to probe for the hardware present in a Linux system like this.id Command
id command shows user and group information for the current user or specified username as shown below.ifconfig Command
ifconfig command is used to configure a Linux systems network interfaces. It is used to configure, view and control network interfaces.ionice Command
ionice command is used to set or view process I/O scheduling class and priority of the specified process.If invoked without any options, it will query the current I/O scheduling class and priority for that process:To understand how it works, read this article: How to Delete HUGE (100-200GB) Files in Linuxiostat Command
iostat is used to show CPU and input/output statistics for devices and partitions. It produces useful reports for updating system configurations to help balance the input/output load between physical disks.ip Command
ip command is used to display or manage routing, devices, policy routing and tunnels. It also works as a replacement for well known ifconfig command.This command will assign an IP address to a specific interface (eth1 in this case).iptables Command
iptables is a terminal based firewall for managing incoming and outgoing traffic via a set of configurable table rules.The command below is used to check existing rules on a system (using it may require root privileges).iw Command
iw command is used to manage wireless devices and their configuration.iwlist Command
iwlist command displays detailed wireless information from a wireless interface. The command below enables you to get detailed information about the wlp1s0interface.kill Command
kill command is used to kill a process using its PID by sending a signal to it (default signal for kill is TERM).killall Command
killall command is used to kill a process by its name.kmod Command
kmod command is used to manage Linux kernel modules. To list all currently loaded modules, type.last Command
last command display a listing of last logged in users.ln Command
ln command is used to create a soft link between files using the-s
flag like this.locate Command
locate command is used to find a file by name. The locate utility works better and faster than it’s find counterpart.The command below will search for a file by its exact name (not *name*):login Command
login command is used to create a new session with the system. You’ll be asked to provide a username and a password to login as below.ls Command
ls command is used to list contents of a directory. It works more or less like dir command.The-l
option enables long listing format like this.lshw Command
lshw command is a minimal tool to get detailed information on the hardware configuration of the machine, invoke it with superuser privileges to get a comprehensive information.lscpu Command
lscpu command displays system’s CPU architecture information (such as number of CPUs, threads, cores, sockets, and more).lsof Command
lsof command displays information related to files opened by processes. Files can be of any type, including regular files, directories, block special files, character special files, executing text reference, libraries, and stream/network files.To view files opened by a specific user’s processes, type the command below.lsusb Command
lsusb command shows information about USB buses in the system and the devices connected to them like this.man Command
man command is used to view the on-line reference manual pages for commands/programs like so.md5sum Command
md5sum command is used to compute and print the MD5 message digest of a file. If run without arguments, debsums checks every file on your system against the stock md5sum files:mkdir Command
mkdir command is used to create single or more directories, if they do not already exist (this can be overridden with the-p
option).more Command
more command enables you to view through relatively lengthy text files one screenful at a time.Check difference between more and less command and Learn Why ‘less’ is Faster Than ‘more’ Commandmv Command
mv command is used to rename files or directories. It also moves a file or directory to another location in the directory structure.nano Command
nano is a popular small, free and friendly text editor for Linux; a clone of Pico, the default editor included in the non-free Pine package.To open a file using nano, type:nc/netcat Command
nc (or netcat) is used for performing any operation relating to TCP, UDP, or UNIX-domain sockets. It can handle both IPv4 and IPv6 for opening TCP connections, sending UDP packets, listening on arbitrary TCP and UDP ports, performing port scanning.The command below will help us see if the port 22 is open on the host 192.168.56.5.netstat Command
netstat command displays useful information concerning the Linux networking subsystem (network connections, routing tables, interface statistics, masquerade connections, and multicast memberships).This command will display all open ports on the local system:nice Command
nice command is used to show or change the nice value of a running program. It runs specified command with an adjusted niceness. When run without any command specified, it prints the current niceness.The following command starts the process “tar command” setting the “nice” value to 12.nmap Command
nmap is a popular and powerful open source tool for network scanning and security auditing. It was intended to quickly scan large networks, but it also works fine against single hosts.The command below will probe open ports on all live hosts on the specified network.nproc Command
nproc command shows the number of processing units present to the current process. It’s output may be less than the number of online processors on a system.openssl Command
The openssl is a command line tool for using the different cryptography operations of OpenSSL’s crypto library from the shell. The command below will create an archive of all files in the current directory and encrypt the contents of the archive file:passwd Command
passwd command is used to create/update passwords for user accounts, it can also change the account or associated password validity period. Note that normal system users may only change the password of their own account, while root may modify the password for any account.pidof Command
pidof displays the process ID of a running program/command.ping Command
ping command is used to determine connectivity between hosts on a network (or the Internet):ps Command
ps shows useful information about active processes running on a system. The example below shows the top running processes by highest memory and CPU usage.pstree Command
pstree displays running processes as a tree which is rooted at either PID or init if PID is omitted.pwd Command
pwd command displays the name of current/working directory as below.rdiff-backup Command
rdiff-backup is a powerful local/remote incremental backup script written in Python. It works on any POSIX operating system such as Linux, Mac OS X.Note that for remote backups, you must install the same version of rdiff-backup on both the local and remote machines. Below is an example of a local backup command:reboot Command
reboot command may be used to halt, power-off or reboot a system as follows.rename Command
rename command is used to rename many files at once. If you’ve a collection of files with “.html” extension and you want to rename all of them with “.php” extension, you can type the command below.rm command
rm command is used to remove files or directories as shown below.rmdir Command
rmdir command helps to delete/remove empty directories as follows.scp Command
scp command enables you to securely copy files between hosts on a network, for example.shutdown Command
shutdown command schedules a time for the system to be powered down. It may be used to halt, power-off or reboot the machine like this.Learn how to show a Custom Message to Users Before Linux Server Shutdown.sleep Command
sleep command is used to delay or pause (specifically execution of a command) for a specified amount of time.sort Command
sort command is used to sort lines of text in the specified file(s) or from stdin as shown belowsplit Command
split as the name suggests, is used to split a large file into small parts.ssh Command
ssh (SSH client) is an application for remotely accessing and running commands on a remote machine. It is designed to offer a secure encrypted communications between two untrusted hosts over an insecure network such as the Internet.stat Command
stat is used to show a file or file system status like this (-f
is used to specify a filesystem).su Command
su command is used to switch to another user ID or become root during a login session. Note that when su is invoked without a username, it defaults to becoming root.sudo Command
sudo command allows a permitted system user to run a command as root or another user, as defined by the security policy such as sudoers.In this case, the real (not effective) user ID of the user running sudo is used to determine the user name with which to query the security policy.sum Command
sum command is used to show the checksum and block counts for each each specified file on the command line.tac Command
tac command concatenates and displays files in reverse. It simply prints each file to standard output, showing last line first.tail Command
tail command is used to display the last lines (10 lines by default) of each file to standard output.If there more than one file, precede each with a header giving the file name. Use it as follow (specify more lines to display using-n
option).talk Command
talk command is used to talk to another system/network user. To talk to a user on the same machine, use their login name, however, to talk to a user on another machine use ‘user@host’.tar Command
tar command is a most powerful utility for archiving files in Linux.tee Command
tee command is used to read from standard input and prints to standard output and files as shown below.time Command
time command runs programs and summarizes system resource usage.top Command
top program displays all processes on a Linux system in regards to memory and CPU usage and provides a dynamic real-time view of a running system.touch Command
touch command changes file timestamps, it can also be used to create a file as follows.tr Command
tr command is a useful utility used to translate (change) or delete characters from stdin, and write the result to stdout or send to a file as follows.uname Command
uname command displays system information such as operating system, network node hostname kernel name, version and release etc.Use the-a
option to show all the system information:uniq Command
uniq command displays or omits repeated lines from input (or standard input). To indicate the number of occurrences of a line, use the-c
option.uptime Command
uptime command shows how long the system has been running, number of logged on users and the system load averages as follows.users Command
users command shows the user names of users currently logged in to the current host like this.vim/vi Command
vim (Vi Improved) popular text editor on Unix-like operating systems. It can be used to edit all kinds of plain text and program files.w Command
w command displays system uptime, load averages and information about the users currently on the machine, and what they are doing (their processes) like this.wall Command
wall command is used to send/display a message to all users on the system as follows.watch Command
watch command runs a program repeatedly while displaying its output on fullscreen. It can also be used to watch changes to a file/directory. The example below shows how to watch the contents of a directory change.wc Command
wc command is used to display newline, word, and byte counts for each file specified, and a total for many files.wget Command
wget command is a simple utility used to download files from the Web in a non-interactive (can work in the background) way.whatis Command
whatis command searches and shows a short or one-line manual page descriptions of the provided command name(s) as follows.which Command
which command displays the absolute path (pathnames) of the files (or possibly links) which would be executed in the current environment.who Command
who command shows information about users who are currently logged in like this.whereis Command
whereis command helps us locate the binary, source and manual files for commands.xargs Command
xargs command is a useful utility for reading items from the standard input, delimited by blanks (protected with double or single quotes or a backslash) or newlines, and executes the entered command.The example below show xargs being used to copy a file to multiple directories in Linux.yes Command
yes command is used to display a string repeatedly until when terminated or killed using [Ctrl + C
] as follows.youtube-dl Command
youtube-dl is a lightweight command-line program to download videos and also extract MP3 tracks from YouTube.com and a few more sites.The command below will list available formats for the video in the provided link.zcmp/zdiff Command
zcmp and zdiff minimal utilities used to compare compressed files as shown in the examples below.zip Command
zip is a simple and easy-to-use utility used to package and compress (archive) files.zz Command
zz command is an alias of the fasd commandline tool that offers quick access to files and directories in Linux. It is used to quickly and interactively cd into a previously accessed directory by selecting the directory number from the first field as follows.That’s it for now! As we mentioned before, there are a countless number of commands in Linux. The list is possibly longer than we can offer. Use the feedback form below to share any useful and frequently used commands missing in this list. 1. tar command examples
Create a new tar archive.$ tar cvf archive_name.tar dirname/
Extract from an existing tar archive.$ tar xvf archive_name.tar
View an existing tar archive.$ tar tvf archive_name.tar
2. grep command examplesSearch for a given string in a file (case in-sensitive search).$ grep -i "the" demo_file
Print the matched line, along with the 3 lines after it.$ grep -A 3 -i "example" demo_text
Search for a given string in all files recursively$ grep -r "ramesh" *
3. find command examplesFind files using file-name ( case in-sensitve find)# find -iname "MyCProgram.c"
Execute commands on files found by the find command$ find -iname "MyCProgram.c" -exec md5sum {} \;
Find all empty files in home directory# find ~ -empty
4. ssh command examplesLogin to remote hostssh -l jsmith remotehost.example.com
Debug ssh clientssh -v -l jsmith remotehost.example.com
Display ssh client version$ ssh -V OpenSSH_3.9p1, OpenSSL 0.9.7a Feb 19 2003
5. sed command examplesWhen you copy a DOS file to Unix, you could find \r\n in the end of each line. This example converts the DOS file format to Unix file format using sed command.$sed 's/.$//' filename
Print file content in reverse order$ sed -n '1!G;h;$p' thegeekstuff.txt
Add line number for all non-empty-lines in a file$ sed '/./=' thegeekstuff.txt | sed 'N; s/\n/ /'
6. awk command examplesRemove duplicate lines using awk$ awk '!($0 in array) { array[$0]; print }' temp
Print all lines from /etc/passwd that has the same uid and gid$awk -F ':' '$3==$4' passwd.txt
Print only specific field from a file.$ awk '{print $2,$5;}' employee.txt
7. vim command examplesGo to the 143rd line of file$ vim +143 filename.txt
Go to the first match of the specified$ vim +/search-term filename.txt
Open the file in read only mode.$ vim -R /etc/passwd
8. diff command examplesIgnore white space while comparing.# diff -w name_list.txt name_list_new.txt 2c2,3 < John Doe --- > John M Doe > Jason Bourne
9. sort command examplesSort a file in ascending order$ sort names.txt
Sort a file in descending order$ sort -r names.txt
Sort passwd file by 3rd field.$ sort -t: -k 3n /etc/passwd | more
10. export command examples
To view oracle related environment variables.$ export | grep ORACLE declare -x ORACLE_BASE="/u01/app/oracle" declare -x ORACLE_HOME="/u01/app/oracle/product/10.2.0" declare -x ORACLE_SID="med" declare -x ORACLE_TERM="xterm"
To export an environment variable:$ export ORACLE_HOME=/u01/app/oracle/product/10.2.0
11. xargs command examples
Copy all images to external hard-drive# ls *.jpg | xargs -n1 -i cp {} /external-hard-drive/directory
Search all jpg images in the system and archive it.# find / -name *.jpg -type f -print | xargs tar -cvzf images.tar.gz
Download all the URLs mentioned in the url-list.txt file# cat url-list.txt | xargs wget –c
12. ls command examples
Display filesize in human readable format (e.g. KB, MB etc.,)$ ls -lh -rw-r----- 1 ramesh team-dev 8.9M Jun 12 15:27 arch-linux.txt.gz
Order Files Based on Last Modified Time (In Reverse Order) Using ls -ltr$ ls -ltr
Visual Classification of Files With Special Characters Using ls -F$ ls -F
13. pwd commandpwd is Print working directory. What else can be said about the good old pwd who has been printing the current directory name for ages.14. cd command examples
Use “cd -” to toggle between the last two directoriesUse “shopt -s cdspell” to automatically correct mistyped directory names on cd15. gzip command examplesTo create a *.gz compressed file:$ gzip test.txt
To uncompress a *.gz file:$ gzip -d test.txt.gz
Display compression ratio of the compressed file using gzip -l$ gzip -l *.gz compressed uncompressed ratio uncompressed_name 23709 97975 75.8% asp-patch-rpms.txt
16. bzip2 command examples
To create a *.bz2 compressed file:$ bzip2 test.txt
To uncompress a *.bz2 file:bzip2 -d test.txt.bz2
17. unzip command examplesTo extract a *.zip compressed file:$ unzip test.zip
View the contents of *.zip file (Without unzipping it):$ unzip -l jasper.zip Archive: jasper.zip Length Date Time Name -------- ---- ---- ---- 40995 11-30-98 23:50 META-INF/MANIFEST.MF 32169 08-25-98 21:07 classes_ 15964 08-25-98 21:07 classes_names 10542 08-25-98 21:07 classes_ncomp
18. shutdown command examples
Shutdown the system and turn the power off immediately.# shutdown -h now
Shutdown the system after 10 minutes.# shutdown -h +10
Reboot the system using shutdown command.# shutdown -r now
Force the filesystem check during reboot.# shutdown -Fr now
19. ftp command examples
Both ftp and secure ftp (sftp) has similar commands. To connect to a remote server and download multiple files, do the following.$ ftp IP/hostname ftp> mget *.html
To view the file names located on the remote server before downloading, mls ftp command as shown below.ftp> mls *.html - /ftptest/features.html /ftptest/index.html /ftptest/othertools.html /ftptest/samplereport.html /ftptest/usage.html
20. crontab command examplesView crontab entry for a specific user# crontab -u john -l
Schedule a cron job every 10 minutes.*/10 * * * * /home/ramesh/check-disk-space
21. service command examplesService command is used to run the system V init scripts. i.e Instead of calling the scripts located in the /etc/init.d/ directory with their full path, you can use the service command.Check the status of a service:# service ssh status
Check the status of all the services.service --status-all
Restart a service.# service ssh restart
22. ps command examples
ps command is used to display information about the processes that are running in the system.While there are lot of arguments that could be passed to a ps command, following are some of the common ones.To view current running processes.$ ps -ef | more
To view current running processes in a tree structure. H option stands for process hierarchy.$ ps -efH | more
23. free command examples
This command is used to display the free, used, swap memory available in the system.Typical free command output. The output is displayed in bytes.$ free total used free shared buffers cached Mem: 3566408 1580220 1986188 0 203988 902960 -/+ buffers/cache: 473272 3093136 Swap: 4000176 0 4000176
If you want to quickly check how many GB of RAM your system has use the -g option. -b option displays in bytes, -k in kilo bytes, -m in mega bytes.$ free -g total used free shared buffers cached Mem: 3 1 1 0 0 0 -/+ buffers/cache: 0 2 Swap: 3 0 3
If you want to see a total memory ( including the swap), use the -t switch, which will display a total line as shown below.ramesh@ramesh-laptop:~$ free -t total used free shared buffers cached Mem: 3566408 1592148 1974260 0 204260 912556 -/+ buffers/cache: 475332 3091076 Swap: 4000176 0 4000176 Total: 7566584 1592148 5974436
24. top command examples
top command displays the top processes in the system ( by default sorted by cpu usage ). To sort top output by any column, Press O (upper-case O) , which will display all the possible columns that you can sort by as shown below.Current Sort Field: P for window 1:Def Select sort field via field letter, type any other key to return a: PID = Process Id v: nDRT = Dirty Pages count d: UID = User Id y: WCHAN = Sleeping in Function e: USER = User Name z: Flags = Task Flags ........
To displays only the processes that belong to a particular user use -u option. The following will show only the top processes that belongs to oracle user.$ top -u oracle
25. df command examplesDisplays the file system disk space usage. By default df -k displays output in bytes.$ df -k Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 29530400 3233104 24797232 12% / /dev/sda2 120367992 50171596 64082060 44% /home
df -h displays output in human readable form. i.e size will be displayed in GB’s.ramesh@ramesh-laptop:~$ df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 29G 3.1G 24G 12% / /dev/sda2 115G 48G 62G 44% /home
Use -T option to display what type of file system.ramesh@ramesh-laptop:~$ df -T Filesystem Type 1K-blocks Used Available Use% Mounted on /dev/sda1 ext4 29530400 3233120 24797216 12% / /dev/sda2 ext4 120367992 50171596 64082060 44% /home
26. kill command examples
Use kill command to terminate a process. First get the process id using ps -ef command, then use kill -9 to kill the running Linux process as shown below. You can also use killall, pkill, xkill to terminate a unix process.$ ps -ef | grep vim ramesh 7243 7222 9 22:43 pts/2 00:00:00 vim $ kill -9 7243
27. rm command examplesGet confirmation before removing the file.$ rm -i filename.txt
It is very useful while giving shell metacharacters in the file name argument.Print the filename and get confirmation before removing the file.$ rm -i file*
Following example recursively removes all files and directories under the example directory. This also removes the example directory itself.$ rm -r example
28. cp command examples
Copy file1 to file2 preserving the mode, ownership and timestamp.$ cp -p file1 file2
Copy file1 to file2. if file2 exists prompt for confirmation before overwritting it.$ cp -i file1 file2
29. mv command examples
Rename file1 to file2. if file2 exists prompt for confirmation before overwritting it.$ mv -i file1 file2
Note: mv -f is just the opposite, which will overwrite file2 without prompting.mv -v will print what is happening during file rename, which is useful while specifying shell metacharacters in the file name argument.$ mv -v file1 file2
30. cat command examples
You can view multiple files at the same time. Following example prints the content of file1 followed by file2 to stdout.$ cat file1 file2
While displaying the file, following cat -n command will prepend the line number to each line of the output.$ cat -n /etc/logrotate.conf 1 /var/log/btmp { 2 missingok 3 monthly 4 create 0660 root utmp 5 rotate 1 6 }
31. mount command examples
To mount a file system, you should first create a directory and mount it as shown below.# mkdir /u01 # mount /dev/sdb1 /u01
You can also add this to the fstab for automatic mounting. i.e Anytime system is restarted, the filesystem will be mounted./dev/sdb1 /u01 ext2 defaults 0 2
32. chmod command examples
chmod command is used to change the permissions for a file or directory.Give full access to user and group (i.e read, write and execute ) on a specific file.$ chmod ug+rwx file.txt
Revoke all access for the group (i.e read, write and execute ) on a specific file.$ chmod g-rwx file.txt
Apply the file permissions recursively to all the files in the sub-directories.$ chmod -R ug+rwx file.txt
33. chown command exampleschown command is used to change the owner and group of a file. \To change owner to oracle and group to db on a file. i.e Change both owner and group at the same time.$ chown oracle:dba dbora.sh
Use -R to change the ownership recursively.$ chown -R oracle:dba /home/oracle
34. passwd command examples
Change your password from command line using passwd. This will prompt for the old password followed by the new password.$ passwd
Super user can use passwd command to reset others password. This will not prompt for current password of the user.# passwd USERNAME
Remove password for a specific user. Root user can disable password for a specific user. Once the password is disabled, the user can login without entering the password.# passwd -d USERNAME
35. mkdir command examples
Following example creates a directory called temp under your home directory.$ mkdir ~/temp
Create nested directories using one mkdir command. If any of these directories exist already, it will not display any error. If any of these directories doesn’t exist, it will create them.$ mkdir -p dir1/dir2/dir3/dir4/
36. ifconfig command examples
Use ifconfig command to view or configure a network interface on the Linux system.View all the interfaces along with status.$ ifconfig -a
Start or stop a specific interface using up and down command as shown below.$ ifconfig eth0 up $ ifconfig eth0 down
37. uname command examplesUname command displays important information about the system such as — Kernel name, Host name, Kernel release number,
Processor type, etc.,Sample uname output from a Ubuntu laptop is shown below.$ uname -a Linux john-laptop 2.6.32-24-generic #41-Ubuntu SMP Thu Aug 19 01:12:52 UTC 2010 i686 GNU/Linux
38. whereis command examples
When you want to find out where a specific Unix command exists (for example, where does ls command exists?), you can execute the following command.$ whereis ls ls: /bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz
When you want to search an executable from a path other than the whereis default path, you can use -B option and give path as argument to it. This searches for the executable lsmk in the /tmp directory, and displays it, if it is available.$ whereis -u -B /tmp -f lsmk lsmk: /tmp/lsmk
39. whatis command examples
Whatis command displays a single line description about a command.$ whatis ls ls (1) - list directory contents $ whatis ifconfig ifconfig (8) - configure a network interface
40. locate command examples
Using locate command you can quickly search for the location of a specific file (or group of files). Locate command uses the database created by updatedb.The example below shows all files in the system that contains the word crontab in it.$ locate crontab /etc/anacrontab /etc/crontab /usr/bin/crontab /usr/share/doc/cron/examples/crontab2english.pl.gz /usr/share/man/man1/crontab.1.gz /usr/share/man/man5/anacrontab.5.gz /usr/share/man/man5/crontab.5.gz /usr/share/vim/vim72/syntax/crontab.vim
41. man command examples
Display the man page of a specific command.$ man crontab
When a man page for a command is located under more than one section, you can view the man page for that command from a specific section as shown below.$ man SECTION-NUMBER commandname
Following 8 sections are available in the man page.- General commands
- System calls
- C library functions
- Special files (usually devices, those found in /dev) and drivers
- File formats and conventions
- Games and screensavers
- Miscellaneous
- System administration commands and daemons
For example, when you do whatis crontab, you’ll notice that crontab has two man pages (section 1 and section 5). To view section 5 of crontab man page, do the following.$ whatis crontab crontab (1) - maintain crontab files for individual users (V3) crontab (5) - tables for driving cron $ man 5 crontab
42. tail command examples
Print the last 10 lines of a file by default.$ tail filename.txt
Print N number of lines from the file named filename.txt$ tail -n N filename.txt
View the content of the file in real time using tail -f. This is useful to view the log files, that keeps growing. The command can be terminated using CTRL-C.$ tail -f log-file
43. less command examplesless is very efficient while viewing huge log files, as it doesn’t need to load the full file while opening.$ less huge-log-file.log
One you open a file using less command, following two keys are very helpful.CTRL+F – forward one window CTRL+B – backward one window
44. su command examplesSwitch to a different user account using su command. Super user can switch to any other user without entering their password.$ su - USERNAME
Execute a single command from a different account name. In the following example, john can execute the ls command as raj username. Once the command is executed, it will come back to john’s account.[john@dev-server]$ su - raj -c 'ls' [john@dev-server]$
Login to a specified user account, and execute the specified shell instead of the default shell.$ su -s 'SHELLNAME' USERNAME
45. mysql command examples
mysql is probably the most widely used open source database on Linux. Even if you don’t run a mysql database on your server, you might end-up using the mysql command ( client ) to connect to a mysql database running on the remote server.To connect to a remote mysql database. This will prompt for a password.$ mysql -u root -p -h 192.168.1.2
To connect to a local mysql database.$ mysql -u root -p
If you want to specify the mysql root password in the command line itself, enter it immediately after -p (without any space).46. yum command examples
To install apache using yum.$ yum install httpd
To upgrade apache using yum.$ yum update httpd
To uninstall/remove apache using yum.$ yum remove httpd
47. rpm command examples
To install apache using rpm.# rpm -ivh httpd-2.2.3-22.0.1.el5.i386.rpm
To upgrade apache using rpm.# rpm -uvh httpd-2.2.3-22.0.1.el5.i386.rpm
To uninstall/remove apache using rpm.# rpm -ev httpd
48. ping command examplesPing a remote host by sending only 5 packets.$ ping -c 5 gmail.com
49. date command examplesSet the system date:# date -s "01/31/2010 23:59:53"
Once you’ve changed the system date, you should syncronize the hardware clock with the system date as shown below.# hwclock –systohc # hwclock --systohc –utc
50. wget command examples
The quick and effective method to download software, music, video from internet is using wget command.$ wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.1.tar.gz
Download and store it with a different name.$ wget -O taglist.zip http://www.vim.org/scripts/download_script.php?src_id=7701
0 comments:
Post a Comment