Bash Basics
Introduction to common Bash commands for file management
List Files and Directories in the current directory: ls
- ls -a: list files and directory including the hidden files i.e: files that start with "."
- ls -l: list files and directory in a human readable sizes in long format
- ls -la: combination of ls -a and ls -l
Create Files and Directories
- touch FILENAME: create a file with name FILENAME
- mkdir DIR_NAME: create a directory with name DIR_NAME
Remove Files and Directories
- rmdir DIR: remove a directory DIR. Only possible when it is empty.
- rm -rf DIR: force recursive removal. Remove DIR and all the files inside. Use with cautions
- rm FILENAME: remove file FILENAME
Copy and Move Files
cp SRC DST: copy from source SRC to destination DST. Can be files or directories
mv SRC DST: move from source SRC to destination DST. Can be files or directories
Other very useful commands
- pwd: print working directory
-
- cd DST: change working directory. Destination DST can be relative or absolute path
-
- nano FILENAME: create/view/edit a small/simple text editor
- wc -l FILENAME: count number of lines a file has
- uniq -c FILENAME: identify unique line of contents in FILENAME
- cat FILENAME: display the contents of the FILENAME in the shell
Additional Tips
- "." for current working directory
- ".." for parent of the current directory
- Absolute path has "/"
- * : refer to all. Can specify argument. e.g: *.java = all java files
- ~ : home directory
- | : pipeline