How To Use Linux Command Line
Linux is one of the most used operating systems in server machines. One advantage of using Linux server is we can remove graphical interface which is not important for operating use. First thing we should learn before using linux for our server is how to use linux command line in daily use. This article will show you basic use of linux command line.
Moving Around the Filesystem
Commands for moving across the filesystem encompass the subsequent.
Pwd: The pwd command permits you to recognize the listing in that you’re positioned (pwd stands for “print working listing”). For instance, pwd within the laptop directory will show ~/Desktop. Note that the GNOME terminal also displays this information inside the title bar of its window.
Cd: The cd command allows you to change directories. When you open a terminal, you will be in your house listing. To move across the filesystem, use cd.
- To navigate for your computing device listing, use cd ~/Desktop
- To navigate into the root listing, use cd /
- To navigate to your own home directory, use cd
- To navigate up one directory stage, use cd ..
- To navigate to the previous listing (or again), use cd –
- To navigate via more than one ranges of directories immediately, use cd /var/www, for example, on the way to take you immediately to the /www subdirectory of /var.
Manipulating Files and Folders
You can manipulate files and folders by means of the usage of the following instructions.
- Cp: The cp command makes a copy of a document for you. For example, cp record foo makes an precise replica of the record whose call you entered and names the copy foo, but the first file will still exist with its unique call. After you use mv, the unique file now not exists, but after you operate cp, that report stays and a brand new reproduction is made.
- Mv: The mv command movements a report to a extraordinary place or renames a document. Examples are as follows: mv record foo renames the authentic report to foo. Mv foo ~/Desktop actions the file foo in your computing device listing however does now not rename it. You have to specify a new filename to rename a record.
To store on typing, you may substitute ~ in vicinity of the home directory. Note: If you’re using mv with sudo, you will no longer be capable of use the ~ shortcut. Instead, you will have to use the entire pathnames for your files.
- Rm: Use this command to get rid of or delete a document for your listing. It does now not work on directories that comprise files.
- Ls: The ls command shows you the documents in your present day directory. Used with certain options, it lets you see document sizes, while documents in which created, and report permissions. For instance, ls ~ indicates you the documents which are in your home directory.
Mkdir: The mkdir command allows you to create directories. For example, mkdir track creates a music directory.
- Chmod: The chmod command changes the permissions at the documents indexed. Permissions are based totally on a reasonably simple version. You can set permissions for user, group, and global, and you may set whether each can read, write, and/or execute the file. For example, if a report had permission to allow every body to read however simplest the person could write, the permissions could read rwxr–r–. To upload or get rid of a permission, you append a + or a – in the front of the precise permission. For example, to feature the functionality for the organization to edit inside the preceding example, you may type chmod g+x file.
- Chown: The chown command allows the person to trade the person and group ownerships of a document. For instance, chown jim document adjustments the possession of the file to Jim.
System Information Commands
System records instructions include the following.
Df: The df command presentations filesystem disk space usage for all walls. The command df-h might be the most useful. It makes use of megabytes (M) and gigabytes (G) in preference to blocks to report. (-h means “human-readable.”)
unfastened: The free command displays the amount of free and used reminiscence in the device. For example, loose -m offers the information using megabytes, which is probably most useful for cutting-edge computer systems.
Pinnacle: The top command presentations statistics on your Linux system, jogging methods, and machine sources, which includes the CPU, RAM, change usage, and total number of responsibilities being run. To go out pinnacle, press Q.
Uname -a: The uname command with the -a option prints all gadget information, consisting of gadget name, kernel name, version, and a few different info. This command is maximum beneficial for checking which kernel you are the use of.
Lsb_release -a: The lsb_release command with the -a alternative prints version information for the Linux release you are going for walks.
For instance: consumer@computer:~$ lsb_release -a
LSB Version: n/a
Distributor ID: Ubuntu
Description: Ubuntu (The Breezy Badger Release)
ifconfig: This reports to your machine’s network interfaces.
Iwconfig: The iwconfig command suggests you any wireless network adapters and the wi-fi-precise records from them, which includes velocity and network connected.
Ps: The playstation command permits you to view all the methods strolling on the system.
The following commands list the hardware for your computer, both of a selected type or with a specific technique. They are maximum useful for debugging when a chunk of hardware does now not feature successfully.
Lspci: The lspci command lists all PCI buses and devices linked to them. This normally consists of network playing cards and sound cards.
Lsusb: The lsusb command lists all USB buses and any related USB gadgets, inclusive of printers and thumb drives.
Lshal: The lshal command lists all devices the hardware abstraction layer (HAL) is aware of approximately, which ought to be maximum hardware in your gadget.
Lshw: The lshw command lists hardware for your device, together with maker, type, and wherein it’s miles connected.
Searching and Editing Text Files
Search and edit textual content documents via using the following commands.
Grep: The grep command permits you to go looking interior a number of files for a particular seek sample after which print matching traces. For instance, grep blah document will look for the text “blah” inside the document after which print any matching strains.
Sed: The sed (or Stream EDitor) command allows search and update of a specific string in a record. For instance, in case you want to find the string “cat” and replace it with “dog” in a record named pets, type
sed s/cat/dog/g pets.
Both grep and sed are extremely powerful applications. There are many incredible tutorials available on the use of them, however right here are some exact Web websites to get you started:
Three different instructions are useful for coping with text.
- Cat: The cat command, quick for concatenate, is beneficial for viewing and including to text files. The easy command cat FILENAME displays the contents of the report. Using cat FILENAME report provides the contents of the first report to the second one.
- Nano: Nano is a simple textual content editor for the command line. To open a record, use nano filename. Commands indexed at the bottom of the screen are accessed thru urgent Ctrl observed via the letter.
- Much less: The much less command is used for viewing text files in addition to widespread output. A not unusual utilization is to pipe another command via less as a way to see all of the output, along with less.
Dealing with Users and Groups
You can use the following instructions to administer users and groups.
- Adduser: The adduser command creates a brand new person. To create a brand new person, absolutely kind sudo adduser $loginname. This creates the user’s domestic listing and default institution. It prompts for a user password after which further information about the consumer.
- Passwd: The passwd command modifications the user’s password. If run through a regular consumer, it will exchange his or her password. If run the use of sudo, it could trade any person’s password. For example, sudo passwd joe adjustments Joe’s password.
- Who: The who command tells you who’s presently logged into the machine.
- Addgroup: The addgroup command provides a new group. To create a new institution, type sudo addgroup $groupname.
- Deluser: The deluser command gets rid of a person from the gadget. To put off the user’s documents and home directory, you need to feature the
-do away with-home choice.
- Delgroup: The delgroup command gets rid of a collection from the device. You can not eliminate a set this is the number one institution of any customers.
Getting Help at the Command Line
This segment presents you with some tips for getting assist at the command line. The instructions –assist and man are the two most critical equipment at the command line.
Virtually all commands understand the -h (or –assist) option, which produces a brief usage description of the command and its alternatives, then exits returned to the command activate. Try man -h or guy –assist to see this in action.
Every command and nearly every application in Linux has a man (manual) record, so finding this type of record is as easy as typing guy command to carry up an extended guide access for the specified command. For example, guy mv brings up the mv (circulate) manual.
Some beneficial hints for using the man command consist of the subsequent.
Arrow keys: Move up and down the man document by using the arrow keys.
Q: Quit back to the command spark off by using typing q.
Man man : man man brings up the manual access for the person command, which is a great region to begin!
Man intro: guy intro is especially useful. It shows the Introduction of User Commands, which is a well-written, pretty brief introduction to the Linux command line.
There also are data pages, that are usually greater in-depth than man pages. Try information data for the advent to information pages.
Searching for Man Files
If you are not positive which command or application you need to use, you may strive to search the person documents.
man -k foo: This searches the person files for “foo”. Try man -ok nautilus to look how this works.
Note: man -okay foo is similar to the apropos command.
man -f foo: This searches most effective the titles of your device’s guy files. Try man -f gnome, for instance.
Note: man -f foo is similar to the what is command.
Sometimes you want to examine or use a couple of files on the identical time. For instance, you might need to delete all .rar documents or move all .Odt files to some other listing. Thankfully, you can use a sequence of wildcards to perform such obligations.
- * fits any quantity of characters. For instance, *.Rar fits any document with the finishing .Rar.
- ? Matches any single character. For example, ?.Rar fits a.Rar but now not ab.Rar.
- [characters] suits any of the characters in the brackets. For instance, [ab].Rar suits a.Rar and b.Rar however not c.Rar.
- [!Characters] matches any characters that aren’t listed. For instance, [!Ab].Rar suits c.Rar however now not a.Rar or b.Rar.
Executing Multiple Commands
Often you can need to execute several commands together, both by walking one after any other or through passing output from one to any other.
If you want to execute a couple of commands in sequence but do not want to bypass output among them, there are two options primarily based on whether or now not you need the following instructions to run simplest if the preceding instructions be successful or no longer. If you want the commands to run one after the opposite regardless of whether or not or now not preceding instructions be triumphant, region a ; between the commands. For example, in case you need to get information approximately your hardware, you may run lspci ; lsusb, which might output statistics to your PCI buses and USB gadgets in series.
However, in case you need to conditionally run the instructions based totally on whether the preceding command has succeeded, insert && between commands. An example of that is building a application from supply, that is historically completed with ./configure, make, and make set up. The instructions make and make set up require that the previous commands have finished correctly, so you might use ./configure && make && make set up.
If you need to bypass the output of one command in order that it is going to the enter of the next, after the character used between the commands, you need something referred to as a pipe, which looks as if a vertical bar or pipe (among each command. For instance, using in the much less lets in you to view the contents of the ls more without difficulty.
Moving to More Advanced Uses of the Command Line
There are an extremely good number of appropriate books accessible for running the command line. In addition, due to the fact most of the command line has not modified in lots of years, a huge body of facts is to be had at the Internet. If you need help with something, regularly, in reality, searching for the command will turn up what you need.
To get you started out, here are a few hints.
A Practical Guide to Linux Commands, Editors and Shell Programming through Mark G. Sobell (Prentice Hall, 2005) is a superb book for any person of the shell in Linux to have on his or her bookshelf.
LinuxCommand.Org is a high-quality Web web page designed to help people new to the use of the command line.
The Linux Documentation Project is an incredible and unfastened aid for many things Linux.
This content changed into excerpted from the brand new 2d version of The Official Ubuntu Book, authored with the aid of Benjamin Mako Hill and Jono publisher 1st baron Verulam, with Ivan Krstic, David Murphy, Jonathan Jesse, Peter Savage and Corey Burger, published by Prentice Hall Professional, July 2007. Copyright 2007 Canonical Ltd., all rights reserved.