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
This command allows you to specify the directory name that you want to move to.
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 ../..”
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
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
Lists all files and subdirectories, except for those that begin with a period, such as .links files.
Lists all files and subdirectories (including those that begin with a period), with owners and sizes.
CREATING, REMOVING, AND MOVING DIRECTORIES
Creates a subdirectory named dirname in the current directory.
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.
Line, word, & char count of filename.
List contents of 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.
Delete (remove) filename
grep ‘asdf’ filename
Outputs lines in filename that match asdf
diff file1 file2
Lists file differences between file1 and file2.
Output beginning of filename.
Output end of filename.
USER MANAGEMENT & INFORMATION
Displays disk quota.
Prints date & time
List logged in users with some information such as their IP and time logged in.
Displays the username of the current user (ie YOU).
Output user information of username.
Display recent commands performed by you.
Submit recent command number n, e.g. !18 repeats the command number 18 in your history list of commands.
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.
- Recursively Delete Files and Retain Folders in Windows
- How To Make and Run Batch Files In Terminal In Mac OSX
- Example FTP Session in UNIX
- How To Print The List of Files in a Folder on the Mac
- How To Create An Anonymous or Limited Access Only Account With MySQL