40 Most Frequently Used UNIX / Linux Commands (part-2)

by Ismail.EL
0 comment



40 Most Frequently Used UNIX / Linux Commands (part-2)

In this article i introduce you with examples a ten most frequently used commands in Linux / UNIX.
in general the lesson is divided into five parts,in each part I give you 10 command:

1. uname command :

Uname command displays important information about current kernel, Host name, Kernel release number,
Processor type, etc.,

Options:
-a, –all
print all information, in the following order, except omit -p and -i if unknown:
-s, –kernel-name
print the kernel name
-n, –nodename
print the network node hostname
-r, –kernel-release
print the kernel release
-v, –kernel-version
print the kernel version
-m, –machine
print the machine hardware name
-p, –processor
print the processor type or “unknown”
-i, –hardware-platform
print the hardware platform or “unknown”
-o, –operating-system
print the operating system
Example:

Linux tutorialspace.com 3.8.0-29-generic #42~precise1-Ubuntu SMP Wed Aug 14 15:31:16 UTC 2013 i686 i686 i386 GNU/Linux

2. ifconfig command :

Use ifconfig command to view or configure a network interface on the Linux system.

-options:
-a     display all interfaces which are currently available, even if down
-v     be more verbose for some error conditions
Interface:
up     This flag causes the interface to be activated.  It is implicitly specified if an address is assigned to the interface.
down   This flag causes the driver for this interface to be shut down.

eth0      Link encap:Ethernet  HWaddr 9c:8e:99:40:41:fa
UP BROADCAST MULTICAST  MTU:1500  Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
lo        Link encap:Local Loopback
inet addr:127.0.0.1  Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING  MTU:65536  Metric:1
RX packets:870 errors:0 dropped:0 overruns:0 frame:0
TX packets:870 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:70768 (70.7 KB)  TX bytes:70768 (70.7 KB)
wlan0     Link encap:Ethernet  HWaddr 68:a3:c4:d5:35:5a
inet addr:192.168.1.3  Bcast:192.168.1.255  Mask:255.255.255.0
inet6 addr: fe80::6aa3:c4ff:fed5:355a/64 Scope:Link
inet6 addr: fd0b:d9d8:9e3d:0:6aa3:c4ff:fed5:355a/64 Scope:Global
inet6 addr: fd0b:d9d8:9e3d:0:f4ae:8a8b:7b1a:c267/64 Scope:Global
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:60852 errors:0 dropped:0 overruns:0 frame:0
TX packets:51027 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:52341597 (52.3 MB)  TX bytes:9429444 (9.4 MB)

display a short list (like netstat -i):

Iface   MTU Met   RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0       1500 0         0      0      0 0             0      0      0      0 BMU
lo        65536 0       870      0      0 0           870      0      0      0 LRU
vmnet1     1500 0         0      0      0 0            66      0      0      0 BMRU
vmnet8     1500 0         0      0      0 0            64      0      0      0 BMRU
wlan0      1500 0     60910      0      0 0         51063      0      0      0 BMRU

Start or stop a specific interface using up and down command as shown below:

3. mkdir command :

mkdir – make directories
-options:
-m, –mode=MODE
set file mode (as in chmod), not a=rwx – umask
-p, –parents
no error if existing, make parent directories as needed
-v, –verbose
print a message for each created directory
-Z, –context=CTX
set the SELinux security context of each created directory to CTX
–help display this help and exit
–version
output version information and exit

Following example creates a directory called Directory under your home directory:

Create parent directories as necessary. When this option is used, no error is reported if a specified DIRECTORY already exists:

4. chown command :

chown command is used to change the owner and group of a file.

To change owner to user1 and group to group1 on a file file1.txt:

To change owner to user1 and group to group1 on a directory1:

* -R to change the ownership recursively.

5. passwd command :

Change your password from command line using passwd.

Super user can use passwd command to reset others password. This will not prompt for current password of the user.

passwd USERNAME

Remove password for a specific user. Root user can disable password for a specific user. Once the password is disabled, the user can login without entering the password.

6. chmod command :

chmod command is used to change the permissions for a file or directory.

Give full access to user and group (i.e r=read, w=write and x=execute ) on a specific file.

Revoke all access for the group (i.e read, write and execute ) on a specific file.

Apply the file permissions recursively to all the files in the sub-directories.

7. mount command :

To mount a file system, you should first create a directory and mount it as shown below.

You can also add this to the fstab for automatic mounting. i.e Anytime system is restarted, the filesystem will be mounted.

/dev/sdb1 /data ext2 defaults 0 2

to unmount file systems you can use the following command
$ umount /data

8. cp command :

cp command main options:
-options:
cp -a     archive files
cp -f     force copy by removing the destination file if needed
cp -i     interactive – ask before overwrite
cp -l     link files instead of copy
cp -L     follow symbolic links
cp -n     no file overwrite
cp -R     recursive copy (including hidden files)
cp -u     update – copy when source is newer than dest
cp -v     verbose – print informative messages

-example:
Copy file1 to file2 preserving the mode, ownership and timestamp.

Copy file1 to file2. if file2 exists prompt for confirmation before overwritting it.

Copy all files and directories in dev recursively to subdirectory bak:

Force file copy:

9. mv command :

mv command is used to move files and directories.

-options:
mv -f     force move by overwriting destination file without prompt
mv -i     interactive prompt before overwrite
mv -u     update – move when source is newer than destination
mv -v     verbose – print source and destination files
man mv     help manual

– example:
Rename file1 to file2. if file2 exists prompt for confirmation before overwritting it.

Move main.c def.h files to /home/usr/rapid/ directory:

Move all C files in current directory to subdirectory bak :

Move all files in subdirectory bak to current directory :

Rename file main.c to main.bak:

Rename directory bak to bak2:

10. cat command :

cat  command is used to display the content of text files and to combine several files to one file.

-syntax:
$ cat [options] file1 [file2…]

-options:
option     description
cat -b     add line numbers to non blank lines
cat -n     add line numbers to all lines
cat -s     squeeze blank lines to one line
cat -E     show $ at the end of line
cat -T     show ^I instead of tabs

-examples:
View text file data:

Combine 2 text files:

Combine 2 text files to another file:

40 Most Frequently Used UNIX / Linux Commands (part-1)

5. Conclusion

In this post, i have explained a 40 Most Frequently Used UNIX / Linux Commands (part-2)
If you have any questions or feedback, feel free to leave a comment.
As always, if you found this post useful, then click like and share it 🙂

21430cookie-check40 Most Frequently Used UNIX / Linux Commands (part-2)

Related Posts

Leave a Comment