Professional Documents
Culture Documents
Linux Basic Commands
Linux Basic Commands
Linux Basic Commands
So, basically, a 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.
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 file
system. It is denoted by a forward slash( / ). The user directory is usually
something like "/home/username".
2. ls — Use the "ls" command to know what files are in the directory
you are in. You can see all the hidden files by using the command “ls -
a”.
Intermediate Commands
1. echo — The "echo" command helps us move some data, usually text
into a file. For example, if you want to create a new text file or add to an
already made text file, 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.
3. nano, vi, jed — nano and vi are already installed text editors in the
Linux command line. The nano command is a good text editor that
denotes keywords with color and can recognize most languages.
And vi is simpler than nano. You can create a new file or modify a file
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 as good, because of its color, so I
recommend jed text editor. We will come to installing packages soon.
4. sudo — A widely used command in the Linux command
line, sudo stands for "SuperUser Do". So, if you want any command to
be done with administrative or root privileges, 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”(not misspelled, it is passwd). Then type in the new root
password.
5. df — Use the df command 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”.
7. tar — Use tar 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. Since it is
a wide topic, here are some examples of tar commands.
9. uname — Use uname 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 — Use apt to work with packages in the Linux command
line. Use apt-get to install packages. This requires root privileges, so use
the sudocommand with it. For example, if you 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 — Use chmod to make a file executable and to change the
permissions granted to it in Linux. Imagine you have a python code
namednumbers.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.
The Linux “tar” stands for tape archive, which is used by large number
of Linux/Unix system administrators to deal with tape drives backup. The tar
command used to rip a collection of files and directories into highly
compressed archive file commonly called tarball or tar, gzip and bzip in Linux.
The tar is most widely used command to create compressed archive files and
that can be moved easily from one disk to another disk or machine to
machine.
/home/tecmint/
/home/tecmint/cleanfiles.sh
/home/tecmint/openvpn-2.1.4.tar.gz
/home/tecmint/tecmint-14-09-12.tar
/home/tecmint/phpmyadmin-2.11.11.3-1.el5.rf.noarch.rpm
/home/tecmint/rpmforge-release-0.5.2-2.el5.rf.i386.rpm
Let’s discuss each option that we have used in the above command for
creating a tar archive file.
/home/MyImages/
/home/MyImages/Sara-Khan-and-model-Priyanka-Shah.jpg
/home/MyImages/RobertKristenviolent101201.jpg
/home/MyImages/Justintimerlake101125.jpg
/home/MyImages/Mileyphoto101203.jpg
/home/MyImages/JenniferRobert101130.jpg
/home/MyImages/katrinabarbiedoll231110.jpg
/home/MyImages/the-japanese-wife-press-conference.jpg
/home/MyImages/ReesewitherspoonCIA101202.jpg
/home/MyImages/yanaguptabaresf231110.jpg
/home/php/
/home/php/iframe_ew.php
/home/php/videos_all.php
/home/php/rss.php
/home/php/index.php
/home/php/vendor.php
/home/php/video_title.php
/home/php/report.php
/home/php/object.html
/home/php/video.php
4. Untar tar Archive File
To untar or extract a tar file, just issue following command using
option x (extract). For example the below command will untar the
file public_html-14-09-12.tar in present working directory. If you want to untar in
a different directory then use option as -C (specified directory).
## Untar files in Current Directory ##
# tar -xvf public_html-14-09-12.tar
/home/public_html/videos/
/home/public_html/videos/views.php
/home/public_html/videos/index.php
/home/public_html/videos/logout.php
/home/public_html/videos/all_categories.php
/home/public_html/videos/feeds.xml
/home/public_html/videos/thumbnails/
/home/public_html/videos/thumbnails/katdeepika231110.jpg
/home/public_html/videos/thumbnails/katrinabarbiedoll2311
10.jpg
/home/public_html/videos/thumbnails/onceuponatime101125.j
pg
/home/public_html/videos/thumbnails/playbutton.png
/home/public_html/videos/thumbnails/ReesewitherspoonCIA10
1202.jpg
/home/public_html/videos/thumbnails/snagItNarration.jpg
/home/public_html/videos/thumbnails/Minissha-Lamba.jpg
/home/public_html/videos/thumbnails/Lindsaydance101201.jp
g
/home/public_html/videos/thumbnails/Mileyphoto101203.jpg
/home/public_html/videos/flv/katrinabarbiedoll231110.flv
/home/public_html/videos/flv/BrookmuellerCIA101125.flv
/home/public_html/videos/flv/dollybackinbb4101125.flv
/home/public_html/videos/flv/JenniferRobert101130.flv
/home/public_html/videos/flv/JustinAwardmovie101125.flv
/home/public_html/videos/flv/Lakme-Fashion-Week.flv
/home/public_html/videos/flv/Mileyphoto101203.flv
/home/public_html/videos/flv/Minissha-Lamba.flv
tecmintbackup.xml
/home/php/index.php
13. Untar Multiple files from tar, tar.gz and tar.bz2 File
To extract or untar multiple files from the tar, tar.gz and tar.bz2 archive file. For
example the below command will extract “file 1” “file 2” from the archive files.
# tar -xvf tecmint-14-09-12.tar "file 1" "file 2"
/home/php/iframe_ew.php
/home/php/videos_all.php
/home/php/rss.php
/home/php/index.php
/home/php/vendor.php
/home/php/video_title.php
/home/php/report.php
/home/php/video.php
18. Check the Size of the tar, tar.gz and tar.bz2 Archive File
To check the size of any tar, tar.gz and tar.bz2 archive file, use the following
command. For example the below command will display the size of archive
file in Kilobytes (KB).
# tar -czf - tecmint-14-09-12.tar | wc -c
12820480
Don’t Miss: Split Large ‘tar’ Archive into Multiple Files of Certain Size
If we’ve missed any example please do share with us via comment box and
please don’t forget to share this article with your friends. This is the best way
to say thanks
Syntax
Examples
Related commands
Description
On Unix-like operating systems, a set
of flags associated with each file determines
who can access that file, and how they can
access it. These flags are called
file permissions or modes, as in "mode of
access." The command name chmod stands
for "change mode." It restricts the way a file
can be accessed.
So 7 is the combination of
permissions 4+2+1 (read, write, and
execute), 5 is 4+0+1 (read, no write, and
execute), and 4 is 4+0+0(read, no write,
and no execute).
Syntax
chmod [OPTION]... MODE[,MODE]... FILE...
Options
-c, --changes Like --verbose, but gives verbose output only when a change is actu
-f, --silent, --quiet Quiet mode; suppress most error messages.
-v, --verbose Verbose mode; output a diagnostic message for every file processed
--no-preserve-root Do not treat '/' (the root directory) in any special way, which is the d
--preserve-root Do not operate recursively on '/'.
--reference=RFILE Set permissions to match those of file RFILE, ignoring any specifie
-R, --recursive Change files and directories recursively.
--help Display a help message and exit.
--version Output version information and exit.
Technical Description
chmod changes the file mode of each
specified FILE according to MODE, which can
be either a symbolic representation of
changes to make, or an octal number
representing the bit pattern for the new
mode bits.
[ugoa...][[+-=][perms...]...]
ls -l file.txt
Examples
chmod 644 file.htm