Linux Basic Commands
Linux Basic Commands
AI Blog
Sometimes, commands are also referred as "programs" since whenever you run a command, 3) The Big Switch
it's the corresponding program code, written for the command, which is being executed. 4) Terminal V/s GUI
5) Imp Commands
Let's learn the must know Linux commands.
6) File Permissions
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
12. Pasting commands into the terminal
13. Printing in Unix/Linux
14. 'pr' command
15. Installing So ware
16. Sending E-mails
17. Cheat Sheet
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Listing files (ls)
If you want to see the list of files on your UNIX or Linux system, use the 'ls' command.
Note:
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
You can use 'ls -R' to shows all the files not only in directories but also subdirectories
NOTE: The command is case-sensitive. If you enter, "ls - r" you will get an error.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
'ls -al' gives detailed information of the files. The command provides information in a columnar
format. The columns contain the following information:
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Listing Hidden Files
Hidden items in UNIX/Linux begin with - at the start, of the
file or directory.
Any Directory/file starting with a '.' will not be seen unless you request for it. To view hidden
files, use the command.
ls -a
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
1. cat > filename
2. Add content
3. Press 'ctrl + d' to return to command prompt.
cat filename
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
cat file1 file2 > newfilename
As soon as you insert this command and hit enter, the files are concatenated, but you do not see
a result. This is because Bash Shell (Terminal) is silent type. It will never give you a confirmation
message like "OK" or "Command Successfully Executed". It will only show a message when
something goes wrong or when an error has occurred.
cat sample
Note: Only text files can be displayed and combined using this command.
Deleting Files
The 'rm' command removes files from the system without confirmation.
mv filename new_file_location
mv sample2 /home/guru99/Documents
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
mv command needs super user permission. Currently, we are executing the command as a
standard user. Hence we get the above error. To overcome the error use command.
sudo command_you_want_to_execute
Sudo program allows regular users to run programs with the security privileges of the superuser
or root.
Sudo command will ask for password authentication. Though, you do not need to know the
root password. You can supply your own password. A er authentication, the system will invoke
the requested command.
Sudo maintains a log of each command run. System administrators can trackback the person
responsible for undesirable changes in the system.
mv filename newfilename
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
NOTE: By default, the password you entered for sudo is retained for 15 minutes per terminal.
This eliminates the need of entering the password time and again.
You only need root/sudo privileges, only if the command involves files or directories not owned
by the user or group running the commands
Directory Manipulations
Creating Directories
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Directories can be created on a Linux operating system using the following command
mkdir directoryname
This command will create a subdirectory in your present working directory, which is usually
your "Home Directory".
For example,
mkdir mydirectory
If you want to create a directory in a di erent location other than 'Home directory', you could
use the following command -
mkdir
For example:
mkdir /tmp/MUSIC
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
will create a directory 'Music' under '/tmp' directory
Removing Directories
To remove a directory, use the command -
rmdir directoryname
Example
rmdir mydirectory
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
will delete the directory mydirectory
Tip: Ensure that there is no file / sub-directory under the directory that you want to delete.
Delete the files/sub-directory first before deleting the parent directory.
Renaming Directory
The 'mv' (move) command (covered earlier) can also be used for renaming directories. Use the
below-given format:
mv directoryname newdirectoryname
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Other Important Commands
To get help on any command that you do not understand, you can type
man
The terminal would open the manual page for that command.
For an example, if we type man man and hit enter; terminal would give us information on man
command
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
The History Command
History command shows all the commands that you have used in the past for the current
terminal session. This can help you refer to the old commands you have entered and re-used
them in your operations again.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
The clear command
This command clears all the clutter on the terminal and gives you a clean window to work on,
just like when you launch the terminal.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Pasting commands into the terminal
Many times you would have to type in long commands on the Terminal. Well, it can be annoying
at times, and if you want to avoid such a situation then copy, pasting the commands can come
to rescue.
For copying, the text from a source, you would use Ctrl + c, but for pasting it on the Terminal,
you need to use Ctrl + Shi + p. You can also try Shi + Insert or select Edit>Paste on the menu
NOTE: With Linux upgrades, these shortcuts keep changing. You can set your preferred
shortcuts via Terminal> Edit> Keyboard Shortcuts.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Printing in Unix/Linux
Let's try out some easy commands which can print files in a format you want. What more, your
original file does not get a ected at all by the formatting that you do. Let us learn about these
commands and their use.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Print, Install Software and Email - Linux Tutorial 7
Watch later Share
'pr' command
This command helps in formatting the file for printing on the terminal. There are many options
available with this command which help in making desired format changes on file. The most
used 'pr' options are listed below.
Option Function
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
-h "header" Assigns "header" value as the report header
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
We want its content to be arranged in three columns. The syntax for the same would be:
pr -x Filename
The '-x' option with the 'pr' command divides the data into x columns.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Assigning a header
The syntax is:
pr -h "Header" Filename
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
As shown above, we have arranged the file in 3 columns and assigned a header
pr -n Filename
This command denotes all the lines in the file with numbers.
These are some of the 'pr' command options that you can use to modify the file format.
Printing a file
Once you are done with the formatting, and it is time for you to get a hard copy of the file, you
need to use the following command:
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
lp Filename
or
lpr Filename
In case you want to print multiple copies of the file, you can use the number modifier.
In case you have multiple printers configured, you can specify a particular printer using the
Printer modifier
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Installing So ware
In windows, the installation of a program is done by running the setup.exe file. The installation
bundle contains the program as well various dependent components required to run the
program correctly.
In Linux/UNIX, installation files are distributed as packages. But the package contains only the
program itself. Any dependent components will have to be installed separately which are
usually available as packages themselves.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
You can use the apt commands to install or remove a package. Let's update all the installed
packages in our system using command -
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
The easy and popular way to install programs on Ubuntu is by using the So ware center as
most of the so ware packages are available on it and it is far more secure than the files
downloaded from the internet.
Sending E-mails
For sending mails through a terminal, you will need to install packages 'mailutils'.
Once done, you can then use the following syntax for sending an email.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
mail -s 'subject' -c 'cc-address' -b 'bcc-address' 'to-address'
Press Cntrl+D you are finished writing the mail. The mail will be sent to the mentioned address.
Summary
You can format and print a file directly from the terminal. The formatting you do on the files
does not a ect the file contents
In Unix/Linux, so ware is installed in the form of packages. A package contains the program
itself. Any dependent component needs to be downloaded separately.
You can also send e-mails from terminal using the 'mail' command
Cheat Sheet
Below is a Cheat Sheet of Linux commands we have learned in this tutorial
Command Description
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
ls Lists all files and directories in the present
working directory
cat file1 file2 > file3 Joins two files (file1, file2) and stores the
output in a new file (file3)
mv file "new file path" Moves the files to the new location
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
rm filename Deletes a file
mv Renames a directory
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
apt-get Command used to install and update
packages
mail -s "Subject" to-address < Filename Command to send email with attachment
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
VISIT THE ACUNETIX WEBSITE
Top Tutorials
About
About Us
Advertise with Us
Write For Us
Selenium Testing Hacking
Contact Us
Career Suggestion
SAP Career
Suggestion Tool
So ware Testing as a
Career
Interesting
Books to Read!
Blog
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Quiz
eBook
Execute online
Execute Java Online
Execute Javascript
SAP
Java
Python
Execute HTML
Jmeter Informatica JIRA
Execute Python
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD