Navigating Linux using CLI
You can use the CLI to perform various tasks such as navigating the file system, managing files and directories and executing commands. This is a useful skill that is beneficial when using Linux and sometimes in IT. Here are some essential commands for navigating Linux using CLI:
- pwd
- Print out the working directory eg, if you are in Documents the output is Documents
- Usage: pwd
- ls
- Lists the contents of the Directory
- Usage:
- ls
- ls -l #detailed list
- ls -a #show hidden files
- ls -ls # detailed list with hidden files
- cd
- Change the current directory or move to the specified directory
- Usage:
- cd /path/to/directory eg cd /home/Documents
- cd .. # Move up one directory
- cd ~ # Move to the home directory
- mkdir
- Create a new Directory
- Usage:
- mkdir dirname
- dirname is the name of the new directory
- touch
- Creates an empty file
- Usage:
- touch filename
- Filename is the name of the empty file
- cp
- Copies files or directories
- Usage:
- cp source destination
- mv
- Moves or renames files or directories
- Usage:
- mv source destination
- mv oldname newname #renaming
- rm
- Removes files or directories
- Usage:
- rm filename
- rm -r dirname
- cat
- Display the content of a file
- Usage:
- cat filename
- echo
- Prints out a message on the terminal
- Usage:
- echo “Hello World!”
- Output ‘Hello World!’
- chmod
- Changes the file permissions
- Usage:
- chmod permissions filename
- Where permissions can be in numeric or Symbolic notation and the filename is the target file
- Example: Numeric notation
- Print out the working directory eg, if you are in Documents the output is Documents
- chown
- Change the owner of a file
- Usage:
- chown newowner filename
- chown user:group filename
- chown :newgroupowner filename
- df
- Displays the disk space usage
- Usage:
- df -h #displays in human-readable format
- nano or vim
- Used as text editors in CLI for creating or editing files
- Usage:
- nano filename
- vim filename
- If the file does not exist, a new file is created with the filename
- wget or curl
- Used to download files or access data from the internet
- Usage:
- wget URL
- curl -O URL
- man
- Displays the manual pages for the different commands
- Usage:
- man command_name