Unix - OS X Commands Referrence - Important Commands

Started by Kalyan, Feb 22, 2008, 06:53 PM

Previous topic - Next topic

Kalyan

UNIX and OS X Commands Reference

cd (change directory)

cd myfolder    Changes the current working directory to "myfolder"

cd ..    Go up one level to the current working directory.

cd ../..    Go up two levels to the current working directory.

cd /    Changes the current working directory to the root directory.

cd ~    Changes the current working directory to your home directory.

mkdir (Make directory)

mkdir IT Acumens   Create a new folder called "IT Acumens" in the current directory.

mkdir /IT Acumens   Create a new folder called "IT Acumens" in the root directory.

mkdir ~/IT Acumens    Create a new folder called "IT Acumens" in your home directory.

ls (list)

ls    list the file names in the current working directory.

ls -l    list the file names with "long" description/information (size, privilages, etc)

ls -a    list "all" file names in the current working directory including the hidden files.

ls -l *.jpg    list the file names ending in ".jpg" and display it in "long" description format(-l)

cp (copy)

cp a.txt itacumens.txt    Copy the file called "a.txt" and name it "itacumens.txt" in the current directory

cp itacumens.cnf /etc/itacumens.cnf    Copy the file "itacumens.cnf" and put it inside the root -> etc folder.

cp itacumens.db ~/a            Copy the file name "itacumens.db" and put it inside my home directory -> a folder

cp ".jpg ~/IT Acumens    Copy all the files with ".jpg" extention and put them inside my home directory -> IT Acumens folder

cp -R ~/Docs /backups/'Docs Backup'    Copy the entire "Docs" directory from my home page and put it inside the root -> backups and call it "Docs backup" (use quotes if you use folder names with space. example: 'Docs Backup' (-R stands for "Recursive")
sudo cp -Rp /Users /UsersBackup    

Copy the entire "Users" folder including subfolders and files, preserve owner, group, permissions, and timestamps and save the new folder in the root -> UsersBackup location. "-Rp" stands for Recursive Preserve:

Recursive: Copy include subfolders and files.

Preserve: Preserve owner, group, permissions, and timestamps information.
(use "sudo" to get root access temporarily.)

mv (Move or Rename)

mv /letter.txt ~/letter.txt    Move the file "letter.txt" from the root directory to the home directory.

mv badletter.txt niceletter.txt    Rename the file "badletter.txt" to "niceletter.txt" in the current directory.

mv Pictures ITAcumens    Rename the folder "Pictures" to "IT Acumens" in the current directory.

mv *.jpg ~/IT Acumens    Move all the files with ".jpg" extention and put them inside my home directory -> IT Acumens folder

rm (Remove)

rm letter.txt    Delete the file "letter.txt" from the current directory.

rm ~/a/*.jpg    Delete all the files with the '.jpg' extention inside your home directory -> "a" folder.

rm -R Temp    Delete the "Temp" directory and all of its contents in the current directory (-R stands for "Recursive")

rm -fr Temp    Delete the "Temp" directory and all of its contents including write-protected files without prompting in the current directory (-f stands for "force" -r stands for "recursive")

find (files and folders)

find ~ -name myletter.doc -  print    Search for the file names "myletter.doc" inside my home directory and print the result to the screen

sudo find / -name mysql -print    Search for the file and folder names "mysql*" starting from the root directory and everywhere within it and print the result to the screen. (use "sudo" to get root access temporarily.)

find . -name myletter.doc -print    Search for the file names "myletter.doc" inside the current directory and print the result to the screen

find . -name 'myletter*' -print    Search for the file names starting "myletter" inside the current directory and print the result to the screen

locate (similar to find)

locate ~ -name myletter.doc    Search for the file names "myletter.doc" inside my home directory and print the result to the screen

pwd (print working directory)

pwd    Displays the pathname of the current working directory.

who (who logged in)

who    Displays who is logged into the system.

who am i    Displays my user name.

who -uH    Displays who is logged into the system including heading "H" and idle time information.

su (set user) - type exit to switch back to your own identity

su    Temporarily become the root user. (this will give you root access privilages and the most control over the OS) - it will prompt you for the administrator password.

su username    Temporarily become another user called "username" (replace "username" with the user that you wish to use as your new identity - this will give you access privilages for the "username") - it will prompt you for the that user's password.

sudo (set user and do . . . . . . ) - similar to su except 'su' will give you prompt but 'sudo' you can start typing commands right after the 'sudo' command.

sudo find / -name mysql -print    Temporarily changes your identity to the root user so you can search for all the files including the once that require root access privilage. It prompts you for administrator/root password

sudo a rm /Users/a/IT Acumens/myphoto.jpg    Temporarily changes your identity to the "a" identity so you can delete a photo named "myphoto.jpg" from the home directory -> IT Acumens folder belonging to a - It prompts you for "a"'s password.

kill

kill 160    Tell the process ID #160 to terminate.

kill -9 160    Terminate the process ID # 160 at once without any hesitation.