Lets's start with the basic command that can be used to perform specific tasks in the directory or folders created on your system.
The 'cd' command can be used to go to a particular directory or folder that exist on your system. For example if you want to go to the Desktop folder of your system, you can use the below command in the terminal.
The pwd command is used to print the current directory path in your terminal. Just write the pwd command in the terminal and press enter and it will print the director path in the terminal.
The 'ls' command will show all the content that a directory or folder has. It will print the names of all directories and files inside the directory from where you ran the command.
DB-Backups Projects image123.png icon.png pdf_file1.pdf logo.png
If you have printed a lot of content in the terminal and want to clear that, you can run the command 'clear' or 'cls' in the terminal.
The 'cp' command is used to copy the files from one folder to another. We need to specify the path of the source file and destination folder in the command.
cp source_file_path destination_path
cp ~/Desktop/source/hello.rtf ~/Desktop/destination
The touch command can be used to create a blank file. For example, if you want to create a text file - test.txt then you can use the below command and it will create the test.txt file in the current directory.
If you want to cut and paste a file from one directory to another directory then you can use the 'mv' command. You need to specify the source file path and destination path to move the file.
mv source_file_path destination_folder_path
mv command example
mv ~/Desktop/source/hello.rtf ~/Desktop/destination
The mkdir command will create a new directory inside the folder you are executing the command.
If you want to create a folder - test using mkdir command, you can use
The rmdir command is used to remove an empty directory from the current directory. You need to specify the directory name and it should be empty to remove via rmdir command.
If test_dir directory is not empty it will not delete the directory and show - Directory not empty message in the terminal.
The rm command can be used to delete files from a directory. For example, if there is file info.txt and you want to delete it using the terminal command then you can use the below command.
To delete a directory and all of its files and directories inside it, you can use the rm -r directory_name terminal command.
rm -r directory_name
The find command can be used to find a file or directory in the current directory. You need to specify the file name that you want to search in the given directory. For example, if you want to search a file named readme.md then you can run the below command in the terminal.
The grep command is used to find a text in all the files that exist inside the current directory. For example, if you want to find a text - 'things' in all the files of a specific directory then you can use below command.
grep -R 'things' .
./data_files/info2.txt:Can make things good ./data_files/info1.txt:All the things
The df command can be used to print the report of disk usage on the system. The disk usage data will be printed in the terminal when you run the df command.
Filesystem 512-blocks Used Available Capacity iused ifree %iused Mounted on /dev/disk1s1 489620264 21652648 276028680 8% 488254 2447613066 0% / devfs 387 387 0 100% 672 0 100% /dev /dev/disk1s6 489620264 173697784 276028680 39% 1084115 2447017205 0% /System/Volumes/Data /dev/disk1s4 489620264 16777296 276028680 6% 8 2448101312 0% /private/var/vm map auto_home 0 0 0 100% 0 0 100% /System/Volumes/Data/home
The du command is used to get the information about the disk usage that the files and directories of the current directory are using.
0 ./hello2 16 ./data_files 32 .
The head command is used to print the first ten lines of a file in the terminal. For example, if you have a text file info.txt and you want to print the first ten lines of it then you can use the below command.
Hello This Is Text file That You Can make things good And We can Use the files
The tail command is used to print the last ten lines of a text file in the terminal. For example, if you have a text file - info.txt and you want to print the last ten lines of it in the terminal then you can use the below command.
To make It more Quick And easy This will gives You An idea About The current structure%
The diff command is used to compare the text of two files line by line. For example, if you have two text files info1.txt and info2.txt and you want to compare the text of these files using the terminal then you can use the below command.
diff info1.txt info2.txt
The tar command is used to archive the files or full directory using the terminal command.
tar -czvf archive_name.tar.gz /path/to/directory-or-file
If you have a folder - data_files that contains multiple files and folders and you want to create an archive file using the tar command then you can use the below command.
tar -czvf data-files.tar.gz data_files
The jobs command can be used to display the jobs that are running on your system along with their status.
The ping command is used to check the connection to the server from your system. Form example, if you want to check the connectivity of a website that has the domain name - domain.com then you can use the below command for that.
The ls [email protected] command can be used to view the permissions assigned to a file. For example, if you have a file info.txt and you want to check the permissions assigned to it then you can use the below command.
ls [email protected] info.txt
[email protected] 1 username staff 41 Mar 11 21:48 info.txt
The chmod command can be used to change the read and write permissions on a file for different users or groups. For example, if you have a file info.txt and you want to change the permission on that you can use the below command.
chmod u=rw,g=r,o=rw info.txt
This will set
u=rw set read and write permission for the file owner.
g=r sets read permission for user groups.
o=rw sets read and write permissions for everyone.