Description of Some Basic Unix Command Line Utilities
cut is a Unix command line utility which is used to extract sections from each line of input — usually from a file.
Extraction of line segments can typically be done by bytes (-b),characters (-c), or fields (-f) separated by a delimiter (-d — the tab character by default). A range must be provided in each case which consists of one of N, N-M, N- (N to the end of the line), or -M (beginning of the line to M), where N and M are counted from 1 (there is no zeroth value).
Assuming a file named “file” containing the lines:
the quick brown fox jumps over the lazy dog
To output the fourth through tenth characters of each line:
$ cut -c 4-10 file
This gives the output:
It requires a mandatory arguments to execute
cut [-b] [-c] [-f list] [-n] [-d delim] [-s] [file
fg is a job control command in Unix and Unix-like operating systems that resumes execution of a suspended process by bringing it to the foreground and thus redirecting its standard input and output streams to the user’s terminal.
it takes the arguments :
fg (process) | (process)…..
Secure copy or SCP is a means of securely transferring computer files between a local host and a remote host or between two remote hosts. It is based on the Secure Shell (SSH) protocol.
Copying file to host:
scp SourceFile user@host:directory/TargetFile
Copying file from host:
scp user@host:directory/SourceFile TargetFile
scp -r user@host:directory/SourceFolder TargetFolder
Note that if the remote host uses a port other than the default of 22, it can be specified in the command. For example, copying a file from host:
scp -P 2222 user@host:directory/SourceFile TargetFile
SSH (Secure Shell)client utility in unix or linux server is used to logging into a remote host and execute commands on the remote machine. The rlogin and rsh commands can also be used to login into the remote machine. However these are not secure. The ssh command provides a secure connection between two hosts over a insecure network. The syntax ssh command is
ssh [-l username] hostname | user@remote-hostname [command]
Let see the examples of ssh command.
1. Version of the SSH command We can find the version of SSH installed on the unix system using the -V option to the ssh. This is shown below:
> ssh -V
OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
2. Copying files between remote host and local host. We can use the scp command to copy the files securely between the local host and remote host using the ssh authentication. To copy the file from local host to remote hosts /var/tmp/ directory, run the below scp command.
scp filename user@remote-host:/var/tmp/
To copy the file from remote hosts /usr/local/bin/ directory to local hosts current directory, run the below scp command.
scp user@remote-host:/usr/local/bin/add.sh .
Uptime is a measure of the time a machine, typically a computer, has been working and available. Uptime is the opposite of downtime.
It is often used as a measure of computer operating system reliability or stability, in that this time represents the time a computer can be left unattended without crashing, or needing to be rebooted for administrative or maintenance purposes
In linux kennel it looks like ;
18:17:07 up 68 days, 3:57, 6 users, load average: 0.16, 0.07, 0.06
Shows how long the system has been on since it was last restarted:
$ cat /proc/uptime
Netstat command displays various network related information such as network connections, routing tables, interface statistics, masquerade connections, multicast memberships etc.,
Example netstat command.
List all the ports(both listening and non listening ports)
# netstat -a | more
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost:30037 *:* LISTEN
udp 0 0 *:bootpc *:*
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 6135 /tmp/.X11-unix/X0
unix 2 [ ACC ] STREAM LISTENING 5140 /var/run/acpid.socket
top is a basic Unix command which is very useful for observing the current state of your Unix system, by default presenting you the list of top users of your system’s resources — CPU shares and memory.
This is the line of top which confirms how many hours (or even days!) your system has been up, shows you the number of logged in users, and reports the average system load numbers for the last minute, 5 minutes and 15 minutes.
top - 13:29:09 up 2 days, 7:13, 4 users, load average: 0.07, 0.02, 0.00
tar command is short for tape archiving, the storing of entire file systems onto magnetic tape, which is one use for the command. However, a more common use for tar is to simply combine a few files into a single file, for easy storage and distribution.
To combine multiple files and/or directories into a single file, use the following command:
tar -cvf file.tar inputfile1 inputfile2
To separate an archive created by tar into separate files, at the shell prompt, enter:
tar -xvf file.tar
zip utility is used to combine as well as compress files in Linux.In this article i have included the uses of zip command and how to secure zip files.
To create a zip file, enter:
zip filename.zip input1.txt input2.txt resume.doc pic1.jpg
To include the contents of a directory in a zip archive, enter:
zip -r backup.zip /data