--- myst: html_meta: description: Quick reference sheet for common Ubuntu command-line commands. --- (command-line-cheat-sheet)= # Command-line cheat sheet This page lists the most common commands in the Ubuntu command line. For full details on any command, run `man ` in your terminal. ## Navigation | Command | Description | Online manual page | |---------|-------------|--------------------| | `pwd` | Print the current working directory | {manpage}`pwd(1)`| | `ls` | List all files and directories in the current directory | {manpage}`ls(1)` | | `ls -l` | Long list, with permissions, owner, size, and date | | | `ls -a` | List all, including hidden files (file names starting with `.`) | | | `ls -la` or `ll` | Long listing including hidden files | | | `ls -ld ` | Show the directory entry itself, not its contents, for directory `` | | `ls -l ` | Show file type, permissions, owner, and size for `` | | `cd ` | Change to the specified directory | _[cd(1posix)](https://manpages.ubuntu.com/manpages/resolute/man1/cd.1posix.html)_| | `cd ..` | Move up to the parent directory | | | `cd ~` | Return to the home directory | | | `cd -` | Return to the previous directory | | | `cd /` | Move to the root directory | | | `cd ../../` | Move up two levels at once | | ## Working with the filesystem | Command | Description | Online manual page | |---------|-------------|--------------------| | `mkdir ` | Create a new directory | {manpage}`mkdir(1)`| | `rmdir ` | Remove an empty directory | {manpage}`rmdir(1)`| | `tree` | Display directory structure as a tree | {manpage}`tree(1)`| | `tree -L ` | Display tree to depth `n` | | ## Working with files | Command | Description | Online manual page | |---------|-------------|--------------------| | `touch ` | Create a new (empty) file, or update the timestamp of an existing file | {manpage}`touch(1)`| | `cp ` | Copy a file from a source (`src`) to a new destination (`dest`) | {manpage}`cp(1)`| | `cp -a ` | Copy a directory recursively, preserving permissions | | | `mv ` | Rename a file or directory | {manpage}`mv(1)` | | `mv /file /file` | Move a file without renaming it | | | `rm ` | Remove a file | {manpage}`rm(1)` | | `rm -r ` | Remove a non-empty directory and all its contents | | | `cat ` | Print the contents of `` to the screen | {manpage}`cat(1)`| | `less ` | View file contents one page at a time | {manpage}`less(1)`| | `head -n 20 ` | Print the first 20 lines of a file (default with no flag is 10) | {manpage}`head(1)`| | `tail -n 20 ` | Print the last 20 lines of a file (default with no flag is 10) | {manpage}`tail(1)`| ## Users, groups, and permissions | Command | Description | Online manual page | |---------|-------------|--------------------| | `chmod ` | Change file permissions (symbolic or numeric notation) | {manpage}`chmod(1)`| | `chown : ` | Change file owner and group | {manpage}`chown(1)`| | `umask` | Show or set the default permissions mask | {manpage}`umask(2)`| | `sudo ` | Run a command with administrator privileges | {manpage}`sudo(8) `| ## Searching | Command | Description | Online manual page | |---------|-------------|--------------------| | `grep ` | Search for lines matching a pattern in a file | {manpage}`grep(1)`| | `grep /etc/passwd` | Look up a user account | | | `grep /etc/group` | Look up group membership | | | `find -name ` | Search for files matching a name pattern | {manpage}`find(1)`| | `which ` | Show the full path to an executable command | {manpage}`which(1) `| | `file ` | Determine the type of a file | {manpage}`file(1)`| ## Getting help | Command | Description | Online manual page | |---------|-------------|--------------------| | `man ` | Open the manual page for a command || | `man man` | Open the manual page for `man` itself | {manpage}`man(1)`| | `man -k ` | Search man page descriptions for a keyword || | ` --help` | Print a brief help summary for a command ||