0% found this document useful (0 votes)
2 views

Unix Commands

The document provides a comprehensive list of Unix commands along with their descriptions, including file management, process control, and user communication commands. It also covers permissions, searching files, and basic networking commands. Additionally, it explains how to check memory usage and the functionality of the grep command for pattern matching in files.

Uploaded by

sreejeevan4499
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Unix Commands

The document provides a comprehensive list of Unix commands along with their descriptions, including file management, process control, and user communication commands. It also covers permissions, searching files, and basic networking commands. Additionally, it explains how to check memory usage and the functionality of the grep command for pattern matching in files.

Uploaded by

sreejeevan4499
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Unix Commands

Command Description

ls Lists all files and directories in the present


working directory

ls - R Lists files in sub-directories as well

ls - a Lists hidden files as well

ls - al Lists files and directories with detailed


information like permissions, size, owner,
etc.

cat > filename Creates a new file

cat filename Displays the file content

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 filename new_file_name Renames the file to a new filename

sudo Allows regular users to run programs with


the security privileges of the superuser or
root

rm filename Deletes a file

man Gives help information on a command

history Gives a list of all past basic Linux


commands list typed in the current
terminal session

clear Clears the terminal

mkdir directoryname Creates a new directory in the present


working directory or a at the specified path
rmdir Deletes a directory

mv Renames a directory

pr -x Divides the file into x columns

pr -h Assigns a header to the file

pr -n Denotes the file with Line Numbers

lp -nc Prints "c" copies of the File


lpr c

lp -d lpr -P Specifies name of the printer

apt-get Command used to install and update


packages

mail -s 'subject' -c 'cc-address' -b 'bcc- Command to send email


address' 'to-address'

mail -s "Subject" to-address < Filename Command to send email with attachment

 diff filename1 filename2 --- compares files, and shows where they differ
 wc filename --- tells you how many lines, words, and characters there are in
a file

chmod options filename --- lets you change the read, write, and execute
permissions on your files.
chmod o+r filename will make the file readable for everyone
chmod o-r filename will make it unreadable for others again.
gzip filename --- compresses files
gunzip filename --- uncompresses files compressed by gzip
gzcat filename --- lets you look at a gzipped file without actually having to gunzip
it
Finding things
ff --- find files anywhere on the system.
grep string filename(s) --- looks for the string in the files.
Finding People
w --- tells you who's logged in, and what they're doing.
who --- tells you who's logged on, and where they're coming from.
finger username --- gives you lots of information about that user
last -1 username --- tells you when the user last logged on and off and from
where.

talk username --- lets you have a (typed) conversation with another user

write username --- lets you exchange one-line messages with another user

elm --- lets you send e-mail messages to people around the world

Name default ports used for DNS, SMTP, FTP, SSH, DHCP
and squid.

Servic
Port
e
DNS 53
SMTP 25
20 (Data transfer), 21 (Connection
FTP established)
SSH 22
67/UDP (dhcp server), 68/UDP (dhcp
DHCP client)
squid 3128
Why is the tar command used?

Suppose you want to extract all the files from the archive named sample.tar.gz,
then the command will be

$ tar -xvzf sample.tar.gz

How to copy a file in Linux?


$ cp <source> <destination>

How to terminate a running process in Linux?

Every process has a unique process id. To terminate the process, we first need
to find the process id. The ps command will list all the running processes along
with the process id. And then we use the kill command to terminate the
process.

$ ps
$ kill 3849

How to write the output of a command to a file?

You can use the redirection operator (>) to do this.

Syntax: $ (command) > (filename)

How would you create a text file without opening it?

The touch command can be used to create a text file without opening it.
The touch command will create an empty file. The syntax is as follows:

$ touch <filename>

What command would you use to check how much


memory is being used by Linux?

You can use any of the following commands:

 free -m
 vmstat
 top
 htop

Explain file permission in Linux.

There are 3 kinds of permission in Linux:

1. Read: Allows a user to open and read the file


2. Write: Allows a user to open and modify the file
3. Execute: Allows a user to run the file.

Explain grep command.

Grep stands for Global Regular Expression Print. The grep command is used
to search for a text in a file by pattern matching based on regular expression

$ grep -c "linux" interview.txt

You might also like