C: Command Line Processing
• These are issued at the command line prompt Simply enter and hit RETURN • Most have flags which modify the execution, indicated by a dash followed by one or more characters
• Basic command line instructions
Task Unix-type Environments To get help man command (manual) help command Change to a new directory cd path (change directory) . represents current dir .. represents parent dir empty path represents home dir To list the contents of a directory ls (list) To make a copy of a source file cp source name destination name (copy) To erase a file rm file name (remove) To rename a file mv old name new name (move) To create a new directory mkdir dir name (make directory) To remove a new directory rmdir dir name (remove directory) To find what your current directory is pwd (print working directory) To put a process to sleep control z To kill a process control c To list currently running jobs jobs To restart a sleeping process % %n wakes process n % wakes most recent active process
1 C: Command Line Processing (2)
• Basic Examples
– Getting help: ∗ To find out the details of how a command works, use man followed by the command. For example, man cd to find out how cd works ∗ help command may also work – Making directories and navigating among them: To create a series of nested directories, starting from your home directory: mkdir labs creates folder labs in your home directory cd labs moves you into folder labs mkdir lab1 creates folder lab1 in folder labs cd lab1 moves you into folder lab1 cd moves you back to your home directory cd labs/lab1 moves you directly from your home directory to lab cd .. moves you one folder higher; i.e., from lab1 to labs – Copying files: ∗ To make a copy of a file: cp myfile.c mycopy.c ∗ When copying, a path may precede the file name To copy myfile.c into directory labs with new name newfile.c: cp myfile.c labs/newfile.c ∗ If the name is not being changed when copying a file to a directory, either of the following work: cp myfile.c labs/myfile.c cp myfile.c labs – Listing files of a folder: ∗ To just list the files in the current directory: ls ∗ To list the files and file details: ls -l ∗ To just list all files in the current directory (including hidden ones): ls -a – Deleting files and directories: ∗ To delete a file: rm myfile.c ∗ To delete many files at once, wild card chararacters can be used · To delete all files: rm ∗ · To delete all files with a .c extension: rm ∗.c ∗ Flag -i will prompt before deleting: rm -i myfile.c ∗ To delete a directory (directory must be empty) rmdir mydir ∗ Flag -d will allow the removal of a directory using rm: rm -d mydir ∗ Flag -r will allow recursive removal of a directory and its contents using rm: rm -r mydir
2