Introduction to the Basic Commands of Linux
Some Basic Commands to Use Linux
In this article we are focusing on some basic Linux commands that are very to useful during working in a terminal and also if you are a user switching from Windows to Linux so these commands are basic utility to know before using.
There are some name of commands and description of commands to know about how they work.
|cat [filename]|| Display file’s contents to the standard output device|
(usually your monitor).
|cd / directory path||Change to directory.|
|chmod [options] mode filename||Change a file’s permissions.|
|chown [options] filename||Change who owns a file.|
|clear||Clear a command line screen/window for a fresh start.|
|cp [options] source destination||Copy files and directories.|
|date [options]||Display or set the system date and time.|
|df [options]||Display used and available disk space.|
|du [options]||Show how much space each file takes up.|
|file [options] filename||Determine what type of data is within a file.|
|find [pathname] [expression]||Search for files matching a provided pattern.|
|grep [options] pattern [filename]||Search files or output for a particular pattern.|
|kill [options] pid||Stop a process. If the process refuses to stop, use kill -9 pid.|
|less [options] [filename]||View the contents of a file one page at a time.|
|ln [options] source [destination]||Create a shortcut.|
|locate filename||Search a copy of your filesystem for the specified filename.|
|lpr [options]||Send a print job.|
|ls [options]||List directory contents.|
|man [command]||Display the help information for the specified command.|
|mkdir [options] directory||Create a new directory.|
|mv [options] source destination||Rename or move file(s) or directories.|
|passwd [name [password]]||Change the password or allow (for the system administrator) to change any password.|
|ps [options]||Display a snapshot of the currently running processes.|
|pwd||Display the pathname for the current directory|
|rm [options] directory||Remove (delete) file(s) and/or directories.|
|rmdir [options] directory||Delete empty directories.|
|ssh [options] user@machine|| Remotely log in to another Linux machine, over the network.|
Leave an ssh session by typing exit.
|tail [options] [filename]||Display the last n lines of a file (the default is 10).|
|tar [options] filename||Store and extract files from a tarfile (.tar) or tarball (.tar.gz or .tgz).|
|top||Displays the resources being used on your system. Press q to exit.|
|touch filename||Create an empty file with the specified name.|
|who [options]||Display who is logged on.|
All this commands are use in Linux operating systems.
After knowing about this commands we are doing some demonstrations of Commands,
1. Command :- ls
The command “ls” stands for (List Directory Contents), List the contents of the folder, be it file or folder, from which it runs.
The command “ls -l” list the content of folder, in long listing fashion.
Note: In Linux file name starting with ‘.‘ is hidden. In Linux every file/folder/device/command is a file. The output of ls -l is:
- d (stands for directory).
- rwxr-xr-x is the file permission of the file/folder for owner, group and world.
- May 8 01:06 is the date and time of last modification.
- And at the end is the name of the File/Folder.
2. Command: lsblk
The “lsblk” stands for (List Block Devices), print block devices by their assigned name (but not RAM) on the standard output in a tree-like fashion.
Command "lsblk" lists the block devices in tree-like fashion.
The “lsblk -l” command list block devices in ‘list‘ structure (not tree like fashion).
Note: lsblk is very useful and easiest way to know the name of New Usb Device you just plugged in, especially when you have to deal with disk/blocks in terminal.
3. Command: uname
The “uname” command stands for (Unix Name), print detailed information about the machine name, Operating System and Kernel.
The “uname -a” command give deatiled information about machine name.
Note: uname shows type of kernel. uname -a output detailed information. Elaborating the above output of uname -a.
- “Linux”: The machine’s kernel name.
- “localhost”: The machine’s node name.
- “3.10.0-19-generic”: The kernel release.
- “#1 SMP”: The kernel version.
- “x86_64”: The architecture of the processor.
- “GNU/Linux”: The operating system name.
4. Command: history
The “history” command stands for History (Event) Record, it prints the history of long list of executed commands in terminal.
5. Command: mkdir
The “mkdir” (Make directory) command create a new directory with name path. However is the directory already exists, it will return an error message “cannot create folder, folder already exists”.
Note: Directory can only be created inside the folder, in which the user has write permission. mkdir: cannot create directory ‘user’: File exists
(Don’t confuse with file in the above output, you might remember what i said at the beginning – In Linux every file, folder, drive, command, scripts are treated as file).
7. Command: touch
The “touch” command stands for (Update the access and modification times of each FILE to the current time). touch command creates the file, only if it doesn’t exist. If the file already exists it will update the timestamp and not the contents of the file.
Note: touch can be used to create file under directory, on which the user has write permission, only if the file don’t exist there.
8. Command: pwd
The command “pwd” (print working directory), prints the current working directory with full path name from terminal.
Note: This command won’t be much frequently used in scripting but it is an absolute life saver for newbie who gets lost in terminal in their early connection with Linux.
9. Command: cd
Finally, the frequently used “cd” command stands for (change directory), it change the working directory to execute, copy, move write, read, etc. from terminal itself.
Note: cd comes to rescue when switching between directories from terminal. “Cd ~” will change the working directory to user’s home directory, and is very useful if a user finds himself lost in terminal. “Cd ..” will change the working directory to parent directory (of current working directory).
10. Command: mv
The “mv” command moves a file from one location to another location.
Note: mv command can be used with wildcard characters. mv should be used with caution, as moving of system/unauthorised file may lead to security as well as breakdown of system.