Unix 1
Unix 1
/
It shows the files /directories in your current directory.
(/images/ls(1).png)
Note:
FEATURED VIDEOS
(/images/sub-directory(1).png)
You can use 'ls -R' to shows all the files not only in directories but also subdirectories
/
(/images/ls-R(1).png)
NOTE: The command is case-sensitive. If you enter, "ls - r" you will get an error.
'ls -al' gives detailed information of the files. The command provides information in a columnar
format. The columns contain the following information:
al(2).png)
Any Directory/file starting with a '.' will not be seen unless you request for it. To view hidden
files, use the command.
ls -a
(/images/ls-
a(2).png)
/
To create a new file, use the command
(/images/cat_filename(1).png)
cat filename
(/images/cat_view_a_file(1).png)
(/images/cat_sample2.png)
(/images/cat_combine.png)
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. Shell Commands 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
(/images/cat_combo.png)
Note: Only text files can be displayed and combined using this command.
Deleting Files
The 'rm' command removes files from the system without confirmation.
rm filename
(/images/linux_rm_command.jpg)
How to delete files using Linux/Unix Commands
/
mv filename new_file_location
mv sample2 /home/guru99/Documents
(/images/mv_error.png)
Ad
Ads bymanager?
Hiring a marketing
Open
Stop seeing this ad
TestGorilla Why this ad?
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. After 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
/
(/images/mv(1).png)
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
(/images/Direct.png)
Enough with File manipulations! Let's learn some directory manipulation Linux basic
commands.
Creating Directories
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
(/images/MKdir-
1.png)
If you want to create a directory in a different location other than 'Home directory', you could
use the following command -
mkdir
For example:
mkdir /tmp/MUSIC
(/images/8-2016/linux-5-1.png)
/
(/images/8-
2016/linux-5-2.png)
Removing Directories
To remove a directory, use the command -
rmdir directoryname
Example
rmdir mydirectory
(/images/rmdir.png)
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.
(/images/rmdir1.png)
Renaming Directory
The 'mv' (move) command (covered earlier) can also be used for renaming directories. Use the
below-given format:
mv directoryname newdirectoryname
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
(/images/man_man.png)
/
(/images/man_man_1.png)
(/images/history.png)
/
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.
(/images/clear.png)
For copying, the text from a source, you would use Ctrl + c, but for pasting it on the Terminal,
you need to use Ctrl + Shift + p. You can also try Shift + 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.
Printing in Unix/Linux
(/images/print.png)
'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
(/images/Tools.png)
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.
(/images/pr_-x.png)
Assigning a header
The syntax is: /
pr -h "Header" Filename
(/images/pr_-header.png)
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.
(/images/pr_-n.png)
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:
lp Filename
or
lpr Filename
In case you want to print multiple copies of the file, you can use the number modifier.
(/images/multiple_prints.png)
In case you have multiple printers configured, you can specify a particular printer using the
Printer modifier
(/images/multiple_printers.png)
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.
/
(/images/VLCPlayer.png)
Using Linux/Unix basic commands, installation files in Linux 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.
(/images/Banshee.png)
You can use the apt commands to install or remove a package. Let's update all the installed
packages in our system using command -
(/images/apt.png) /
The easy and popular way to install programs on Ubuntu is by using the Software center as
most of the software packages are available on it and it is far more secure than the files
downloaded from the internet.
(/images/SoftwareCenter.png)
Once done, you can then use the following syntax for sending an email.
(/images/mail.png)
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 affect the file contents
In Unix/Linux, software 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' network commands. It is very
useful Linux command.
Command Description
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
mv Renames a directory
mail -s "Subject" to-address < Filename Command to send email with attachment
(https://bit.ly/2ExOyrf)
/
Acunetix, the developers of dead-accurate web application
security scanners have sponsored the Guru99 project to
help scan for over 4500 web vulnerabilities accurately and
at top speed.
Unix Tutorials
3) The Big Switch (/linux-differences.html)
7) Redirection (/linux-redirection.html)
/
(https://www.facebook.com/guru99com/)
(https://twitter.com/guru99com)
(https://www.linkedin.com/company/guru99/)
(https://www.youtube.com/channel/UC19i1XD6k88KqHlET8atqFQ)
(https://forms.aweber.com/form/46/724807646.htm)
About
About Us (/about-us.html)
Advertise with Us (/advertise-us.html)
Write For Us (/become-an-instructor.html)
Contact Us (/contact-us.html)
Career Suggestion
SAP Career Suggestion Tool (/best-sap-module.html)
Software Testing as a Career (/software-testing-career-
complete-guide.html)
Interesting
eBook (/ebook-pdf.html)
Blog (/blog/)
Quiz (/tests.html)
SAP eBook (/sap-ebook-pdf.html)
Execute online
Execute Java Online (/try-java-editor.html)
Execute Javascript (/execute-javascript-online.html)
Execute HTML (/execute-html-online.html)
Execute Python (/execute-python-online.html) /
© Copyright - Guru99 2021
Privacy Policy (/privacy-policy.html) | Affiliate
Disclaimer (/affiliate-earning-disclaimer.html) | ToS
(/terms-of-service.html)