Common Useful UNIX Commands

If you’re new to UNIX-based systems (e.g. Linux), the interface can be daunting, especially since there’s no GUI, and you might need to use the shell command line interface to remotely access a computer.

There are a few basic UNIX commands for performing common tasks that you should know of, which allows you to navigate and interact with the system.

MOVING & CHANGING DIRECTORIES

cd dirname

This command allows you to specify the directory name that you want to move to.

Examples:
cd public_html
cd home/alvin

cd ..

Moves one level up from the current directory. Take note of the space between “cd” and the two periods. This is different from Windows, where “cd..” (without the space) would work too. For example, if you are in /home/alvin, use this command to change your folder to /home.

If you want to move up 2 levels, then use “cd ../..”

cd

Changes directories to your default login directory. In UNIX systems, you are automatically placed in your login directory, or home directory when you log on. Performing this command brings you back to that login directory.

IDENTIFYING THE CURRENT DIRECTORY

pwd

Sometimes you need to know what directory you are in. This command in UNIX shows you what directory you are in currently.

LISTING THE CONTENTS OF THE CURRENT DIRECTORY

ls

Lists all files and subdirectories, except for those that begin with a period, such as .links files.

ls -al

Lists all files and subdirectories (including those that begin with a period), with owners and sizes.

CREATING, REMOVING, AND MOVING DIRECTORIES

mkdir dirname

Creates a subdirectory named dirname in the current directory.

rmdir dirname
Removes the subdirectory named dirname from the current directory.

mv dir1 dir2

Moves (or when you look at it from a different angle, renames) the subdirectory (and its contents) from dir1 to dir2. E.g. “mv notes ../notes” will move the notes folder up one level.

FILE MANIPULATION

wc filename

Line, word, & char count of filename.

cat filename

List contents of filename.

more filename

List filename contents by screen.

cat file1 file2 >file3

Concatenates files file1 & file2 into file3.

cmp file1 file2

Compares files file1 and file2.

cp file1 file2

Copy file file1 into file2.

split [-n] filename

Split filename into n-line pieces

mv file1 file2

Rename file file1 as file2.

rm filename

Delete (remove) filename

grep ‘asdf’ filename

Outputs lines in filename that match asdf

diff file1 file2

Lists file differences between file1 and file2.

head filename

Output beginning of filename.

tail filename

Output end of filename.

USER MANAGEMENT & INFORMATION

quota

Displays disk quota.

date

Prints date & time

who

List logged in users with some information such as their IP and time logged in.

whoami

Displays the username of the current user (ie YOU).

finger username

Output user information of username.

history

Display recent commands performed by you.

!n

Submit recent command number n, e.g. !18 repeats the command number 18 in your history list of commands.

passwd

Changes your password.

CHANGE GROUP AFFILIATION OF DIRECTORIES OR FILES

Note: You must own the file or directory you want to change and you must belong to group you are changing it to.

chgrp groupname filename

Changes group affiliation of filename to groupname.

chgrp -R groupname dirname

Changes group affiliation of dirname and all files within dirname to groupname.

GIVE GROUP MEMBERS WRITE PRIVILEGES

Note: You must own the file or directory you want to change.

chmod g+w filename

Gives the group write privileges to filename. Any member of the group affiliated with filename can then change or delete the file. Or, use g-w to remove group write privileges.

chmod -R g+w dirname

Gives the group write privileges to all files within dirname. Any member of the group affiliated with dirname can then change or delete any file within dirname. Or, use g-w to remove group write privileges.

Similar Posts:

Alvin Poh lives in Singapore, and is interested in marketing, techy stuff, and likes to just figure out how the two can work with each other. He can also be found on Google+.

Leave a reply:

Your email address will not be published.


*

Sliding Sidebar