Basic Unix directory commands
- Notes:
- • In Unix it matters whether you type upper or lowercase letters.
- • Press the Enter/Return key after typing each command.
Commands to find out where you are
- pwd
- Prints current directory. Use to check directory in which you are working.
- whoami
- For people who use multiple IDs, tells you which ID you are using.
Commands to get information about contents of current directory
Use options -l, -a, -t, -g in any combination or order as shown in examples.
- ls
- Lists files and directories in current directory.
- ls -l
- Lists files and directories and details about them.
- ls -a
- Lists files and directories and hidden files.
- ls -t
- Lists files and directories in order by last modified date.
- ls -g
- Lists files and directories and which group owns them.
- ls -la
- Lists files and directories, including hidden files, and gives information
about them
- ls -latg
- Lists files and directories showing all options.
- ls p*
- Lists any files in the current directory that begin with the letter p. The
asterisk (*) is used as a wild card. It replaces one or more characters in
a file name. For example, *p* looks for any file with the letter p anywhere
in the name.
Commands to add or delete directories or files
- mkdir directory1
- Makes a directory and names it directory1.
- rmdir directory1
- Removes the directory named directory1. (Note: You cannot remove a directory
unless it is empty.)
- vi file1
- Makes a file named file1 and places you in the "vi" editor. If you only
want to make a file as a placeholder, type :wq (colon and
letters w and q) and then press the Enter/Return key to leave
the vi editor.
- rm file1
- Removes the file named file1 from the current directory.
- rm *
- Removes all files from the current directory.
Commands to move from one directory to another
- cd ..
- Moves one directory above your current location.
- cd directory1
- Moves to a directory named directory1 in the current directory.
- cd ../directory_name
- Moves one directory above current directory and then to directory named.
Commands to move and copy files
- mv file1 file2
- Moves file1 into file2. If file2 has not been created, it creates file2
and moves the contents of file1 into it. If file2 exists, its contents are
replaced by the contents of file1. In all cases, file1 no longer exists.
- mv file1 directory_name
- Moves the file named file1 into the directory named.
- cp file1 file2
- Copies the contents of file1 into file2. Leaves file1 as is.
Command to print files to your screen
- more file1
- Prints the contents of file1 on your screen one screen at a time. Press
the space bar to view the next screen.
See Basic Unix vi editor commands for quick vi editor
commands.