UNIX/LINUX COMMAND CHEAT SHEET (Part 1)

Posted by

FILE COMMANDS:

COMMAND DESCRIPTION
ls List items [files and directories] in the current directory.
ls dir List all the items in the directory dir. Replace dir with the name of the directory that you want to list the items of.
cd dir Change directory to dir. Replace dir with the name of the directory that you want to list the items of.
cd .. Moves up one directory in the file tree structure.
(Example:
/home/dir1/dir2 > cd ..
Returns  (/home/dir1>))
cd / Moves to the root directory.
Changes the current directory as the root directory .
cd ~ Moves to your home directory.
pwd Displays present working directory.
mkdir dir  Create a new directory named dir.
rm file Remove the file named file.
rm -r dir|file Remove directory named dir and sub-directories inside dir recursively (-r recursively)
cp source destination Copy file from source to destination.
mv source destination Move file from source to destination.
who Displays the list of users currently logged in.
whoami

Displays the user id of the currently logged in user.

man <command_name>

Displays the manual of the command_name.

which <command_name>

Returns the path names of the files (or links) which would be executed in the current environment for the particular command_name

type <command_name>

To check if the command_name is a built-in command or external binary file.

touch file(s)

 Create empty file(s).

cat > filename

Create a file named filename and edit its contents.

cat file(s)

Display the contents of file(s) on standard output usually the terminal.

cat source > destination

Copies the contents of source to destination but OVER RIDES the existing contents of destination.

cat source >> destination

Appends the contents of source to destination but DOES NOT OVER RIDE the existing contents of destination.

ln file1 file2 Creates a hard link to file1 named as file2
ln -s file1 file2 Creates a soft link/symbolic link to file1 named as file2

less filename

 View file named filename with page navigation.

head filename

Output the first 10 lines of the file named as filename.

tail filename

Output the last 10 lines of the file named as filename.

vim/vi filename

Edit file named as filename.

echo $$

Returns the process ID (PID) of the current process.

PROCESS COMMANDS:

kill pid

kill process with id as pid

kill -9 pid

Forcefully kill process with id as pid

ps Display currently active processes
top

Display all running processes

Advertisements

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s