Contact for queries :

Login

  UpComing Live WebEx Workshop Series

Basic Linux Commands for Everyday Usage

1.  List the contents of the current directory:

# ls
Desktop Documents Downloads Music Pictures Public Templates
Videos

2. Show the current location:

# pwd
/home/user01

Presently, you are in user01’s home directory, so the output of the ls command was all directories that belong to user01. Let’s move out of user01’s home directory into one of the subdirectories. Using the cd
command, you can move between different directories.
3. Move down one level into the Documents directory:

# cd Documents/

Note: The trailing slash (/) is optional when you’re using the cd command. It indicates that the name being specified is a directory.
4. Now view the current location again:

# pwd
/home/user01/Documents

What if you want to move up one level to the directory you just came from? If you use ls, you don’t see the user01 directory listed. You can, however, view two special directories.
5. View all hidden directories with the ls –a command:

# ls -a
. ..

Notice what seems like just a bunch of dots? They actually stand for two special types of directories. The first—the single .—stands for the current directory. The second—double ..—is the directory above where you
currently are located.
6.To get back to the previous user01 directory, use the following:

# cd ..

7. Verify with the pwd command:

# pwd
/home/user01

 
8. Check the file type of test1:

# file test1
test1: empty

9. Check the type of the password file on the system:

# file /etc/passwd
passwd: ASCII text
 

10. View the beginning of the messages log file:

# head /var/log/messages
Dec 5 03:13:06 RHEL01 dhclient: DHCPREQUEST on eth0 to
172.27.100.163 port 67
Dec 5 03:13:10 RHEL01 dhclient: DHCPREQUEST on eth0 to  255.255.255.255 port 67
Dec 5 03:13:20 RHEL01 dhclient: DHCPREQUEST on eth0 to 172.27.100.163 port 67
Dec 5 03:13:29 RHEL01 dhclient: DHCPREQUEST on eth0 to 255.255.255.255 port 67
Dec 5 03:13:30 RHEL01 dhclient: DHCPREQUEST on eth0 to 172.27.100.163 port 67
Dec 5 03:13:43 RHEL01 dhclient: DHCPREQUEST on eth0 to 255.255.255.255 port 67
Dec 5 03:13:44 RHEL01 dhclient: DHCPREQUEST on eth0 to 172.27.100.163 port 67
Dec 5 03:13:50 RHEL01 dhclient: DHCPREQUEST on eth0 to 255.255.255.255 port 67

11. View the end of the messages log file:

# tail /var/log/messages
Dec 11 08:11:04 RHEL01 dhclient: DHCPDISCOVER on eth0 to
255.255.255.255 port 67 interval 13
Dec 11 08:11:04 RHEL01 dhclient: DHCPOFFER from 172.27.100.163
Dec 11 08:11:04 RHEL01 dhclient: DHCPREQUEST on eth0 to
255.255.255.255 port 67
Dec 11 08:11:04 RHEL01 dhclient: DHCPACK from 172.27.100.163
Dec 11 08:11:04 RHEL01 NET[26281]: /sbin/dhclient-script : updated
/etc/resolv.conf
Dec 11 08:11:04 RHEL01 dhclient: bound to 172.27.100.226 — renewal
in 40864 seconds.
Dec 11 08:18:00 RHEL01 abrt[26389]: saved core dump of pid 26388
(/usr/libexec/fprintd) to /var/spool/abrt/ccpp-129207348026388.
new/coredump (757760 bytes)
Dec 11 08:18:00 RHEL01 abrtd: Directory ‘ccpp-1292073480-26388’
creation detected
Dec 11 08:18:00 RHEL01 abrtd: Crash is in database already (dup of
/var/spool/abrt/ccpp-1291114420-26066)

 
12. Copy the log file into the user01 home directory:

# cp /var/log/messages /home/user01

13. You also could use the following:

# cp /var/log/messages .

Remember that the dot (.) represents the current location. After the messages log file is copied over, you should probably rename it for safekeeping.
14. Rename the file by specifying the filename and the new name of the file:

# mv messages messages.bak

15. With the file renamed, move it to the test directory for safekeeping:

# mv messages.bak test/

Because you specified a directory this time, the file was moved instead of renamed. You can also verify that the file was moved correctly.
16  Deleteing a file i.e. messages.bak

# cd test
# rm messages.bak
rm: remove regular file `messages.bak’? y

Notice that you are prompted to delete the file? By using the –f option, you can skip the confirmation. While you’re deleting things, also remove the test directory.
17. Delete a directory and it’s subcontinents recursively

# cd ..
# rm -Rf test/

 
18. View file permissions for user01’s home directory:

# ll /home/user01
total 32
drwxr-xr-x. 2 user01 user01 4096 Dec 11 07:43 Desktop
drwxr-xr-x. 2 user01 user01 4096 Dec 11 07:43 Documents
drwxr-xr-x. 2 user01 user01 4096 Dec 11 07:43 Downloads
-rw-rw-r–. 1 user01 user01 0 Dec 11 07:44 file1
-rw-rw-r–. 1 user01 user01 0 Dec 11 07:44 file2
drwxr-xr-x. 2 user01 user01 4096 Dec 11 07:43 Music
drwxr-xr-x. 2 user01 user01 4096 Dec 11 07:43 Pictures
drwxr-xr-x. 2 user01 user01 4096 Dec 11 07:43 Public
drwxr-xr-x. 2 user01 user01 4096 Dec 11 07:43 Templates
drwxr-xr-x. 2 user01 user01 4096 Dec 11 07:43 Videos

 
19.  Change the owner of file1 from user01 to user02:

# chown user02 file1

20. Change the group of file2 from user01 to user02:

# chown :user02 file2

21. Now check the permissions again:

# ll
-rw-rw-r–. 1 user02 user01 0 Dec 11 07:44 file1
-rw-rw-r–. 1 user01 user02 0 Dec 11 07:44 file2

 
22.  Change the permissions in the “other” section to allow write access to
this file:

# chmod 666 file1

November 14, 2015

0 responses on "Basic Linux Commands for Everyday Usage"

Leave a Message

Your email address will not be published. Required fields are marked *

About iGURKUL

IGURKUL I.T. Training Hub offering various Career Certification courses in Computer Networking, Unix, Linux, Cloud Computing and DevOps Technologies. With its rich experience in IT training service sector, iGURKUL has been able to set Industry best practices in IT Training for the past five years.

In Past five years, more than 5000 professionals have been trained by iGURKUL for System administration, Cloud Computing and DevOps Skill set through our Online Training portal www.unixadminschool.com. And , each day , more than 10000 working professionals from all over the globe visiting our knowledge base www.unixadminschool.com/blog for the best practices and Knowledge learning.

top
copyright protected - 2011 © igurkul I.T. solutions. All rights reserved.