The 13 Most used BASH COMMAND

Long Do
2 min readDec 29, 2020

--

Bash command is stupid, but high performance.

1. ls

The ls command allows you to quickly view all files within the specified directory.

ls                     // Show unhidden file and folder
ls [directory_name] // Show unhidden file and folder in specify
ls -a // Show all hidden/unhidden file/folder
ls -l // Show in line with detail

2. echo

prints text to the terminal window

echo "Hello World"         // print text Hello World
echo "$current_date" // print variable current_date in string

3. touch

Creates files

touch hello.txt           // Create hello.txt file
touch -a hello.txt // Change access time to current time
touch -m hello.txt // Change modified time to current time
touch -t YYMMDDHHMM fileName // Create file with created time
// Update the created time
touch -r second_file_name first_file_name

4. mkDir

create directories

mkdir hello                  // Create hello directory
mkdir hello/world // Error
mkdir -p hello/world // Create directory hello, hello/world
mkdir -m a=rwx hello // Update the permission

5. grep

search text for patterns specified by the user

grep [options] pattern [files]grep "hello" hello.txt           // Find all line include text hello
grep -i "hello" hello.txt // Find all line include "hello", "HELLO", "HEllo", ... (string case insensitively)
grep -c "hello" hello.txt // Display the number result
grep -w "hello" hello.txt // Matching the whole word "hello"
grep -n "hello" hello.txt // Show line number
grep -e "hello" -e "world" hello.txt // Find multiple
grep "[a-zA-Z][0-9]" hello.txt // Find all line include char before num

6. man

Show document of other command

man grep       // Show document of grep command
man touch // Show document of touch command

7. pwd

print current directory path

pwd

8. mv/cp

move or rename directories. copy files and directories

mv hello.txt hello/hello.txt     // Move file
mv hello.txt world.txt // rename file
mv -f hello.txt hello/hello.txt // Force move file
mv -n hello.txt hello/hello.txt // Not move if des exist
cp hello.txt hello/hello.txt // Copy file

9. rm/rmdir

remove files/directories

rm hello.txt          // Remove file Hello.txt
rm -rf hello // Remove Directory Hello
rmdir hello // Remove empty directory

10. less/cat

view files without opening an editor

less hello.txt        // Show content in terminal
cat hello.txt // Show content in terminal

11. >, |

Redirect output

ls > hello.txt            // Write list of file to hello.txt
ls | grep "hello" // Find all directory, file name include "hello"

12. head/tail

Display top/end (default 10 lines) of file

head hello.txt      // Display first 10 lines of file
tail hello.txt // Display end 10 lines of file
head -3 hello.txt // Display first 3 lines of file
head -5 hello.txt // Display end 5lines of file

13. chmod

Change the file/folder permission

chmod 777 hello.txt   // Set full permission for everyone
chmod +x hello.txt // Set read/write permission

14. history

quickly identify past commands that you’ve used.

Hope this commands useful to you!

--

--

Long Do
Long Do

Written by Long Do

Better code, better world

No responses yet