Common Linux Commands (1)

1. cd
cd: Change directory
Change the working directory. The commands cd and ls are probably the two most used commands, especially for users unfamiliar with the Linux directory structure.
cd /  # Enter the root directory
cd -  # Return to the last directory
cd  # Return to the home directory
cd ~ # Return to the home directory
cd ../ # Return to the parent directory

2. ls
ls: List files
-a  List all files including hidden files that start with .
-A  List all files except for . and ..
-l  List detailed information about files
-c  Sort by ctime
-t  Sort by file modification time
--color[=WHEN] Use color to distinguish file types, WHERE can be 'never', 'always', or 'auto'

3. pwd
print working directory
$ pwd
/home/name

4. sh
Run script command. A script is a file that contains many commands. You can run a script file using sh. For example, if there are multiple sh files in the directory, you can run them all at once.
$ sh a1.index.sh; sh a2.fasqc.sh

5. cp
cp: Copy file
Copy and paste files.
-b  Backup before overwriting
-f  Force overwrite without asking if it exists
-i  Ask whether to overwrite if it exists
-u  Only overwrite if the source file is newer
-t  Move multiple source files to a single directory, with the directory parameter first and file parameters after
cp a1.txt a2.txt

6. mv
mv: Move file
Move files, similar to cut and paste in Windows. If you cut and paste to the same directory, it is a rename operation.
-b  Backup before overwriting
-f  Force overwrite without asking if it exists
-i  Ask whether to overwrite if it exists
-u  Only overwrite if the source file is newer
-t  Move multiple source files to a single directory, with the directory parameter first and file parameters after
mv a1.txt ../

7. rm
rm: Remove file
Delete files.
-r  Remove directories
-f  Delete without prompting
-i  Prompt before deleting
-v  Show detailed progress
Note! Files deleted in command line mode cannot be recovered.
rm -rf *.txt  # Delete all files ending with .txt in the directory

8. ln
ln: Link files
Create link files, including soft links and hard links. Soft links are more commonly used, similar to shortcuts in Windows.
-s  Create a soft link
-v  Show detailed processing
ln -s /name/Example ./ # Create a shortcut for /name/Example directory in the current directory

9. mkdir
mkdir: Make directory
Create a folder.
-p  Create directories recursively, creating parent directories if they do not exist
-m  Customize the permissions of the created directory
-v  Show detailed information about the created directory
mkdir rnaseq # Create a directory named rnaseq

10. cat
cat: Concatenate
One function of cat is to view files, generally for smaller files with less than one screen of lines, not exceeding two screens; another function is to merge multiple files, usually combined with redirection to create a new file or append the content of one file to another.
$ cat a1.fastqc.sh fastqc *.gz # Merge files
cat a1.txt a2.txt > all.txt

Leave a Comment