Table of contents
- Beginning Linux command
- What is the Linux command to:
- π List all the files or directories, including hidden files. π
- π Create a nested directory A/B/C/D/E. π
- π View the contents of a file. π
- π Change the access permissions of files. π
- π Check the command history to view the commands you have executed so far. β³
- π Remove a directory/folder. ποΈ
- π Create a fruits.txt file and view its content. ππ.
- π Add content to the file βοΈπ.
- π Display the specific line in the file.
- π Find the difference between the contents of the fruits.txt and Colors.txt files. ππ¨
- let's connectβ€οΈ:-
Beginning Linux command
Here there are some of the basic linux command :-
pwd
- Print Working Directory: Displays the current directory.ls
- List Files and Directories: Lists the files and directories in the current directory.cd
- Change Directory: Changes the current directory to the specified location.mkdir
- Make Directory: Creates a new directory.rm
- Remove: Deletes files or directories.cp
- Copy: Copies files or directories to a specified location.mv
- Move or Rename: Moves files or directories to a new location or renames them.cat
- Concatenate: Displays the contents of a file.find
- used to search for files and directories . It allows you to locate files by their names, types, sizes, modification times, and other attributes.chmod
- Change Mode: Changes the permissions of a file or directory.
diff
- To find the difference between two files
What is the Linux command to:
π Check your current/present working directory. π
pwd
command is used.
π List all the files or directories, including hidden files. π
ls
is used to list the file and directory.ls -a
is used to list the hidden files and directories as well.
π Create a nested directory A/B/C/D/E. π
mkdir -p
is used for nested directories. Here,-p
make parent directories as needed
π View the contents of a file. π
cat <file_name>
is used.
π Change the access permissions of files. π
chmod +rwx <file_name>
for adding read, write and execution permissions, andchmod -rwx <file_name>
for removing the read , write, and execution permissions.
NOTE :- You may also employ a single flag at a time.
+r for giving read permission
+w for giving written permission
+x for giving execute permission
I have created the hello.txt file using the command touch <file_name>
. Initially check the permission using the ls-l
After giving the execution permissions.
use ls -l
and see what happens in ππ
π Check the command history to view the commands you have executed so far. β³
history
command is used.
π Remove a directory/folder. ποΈ
rm -r <directory/folder name>
This command is also capable of removing the files.
π Create a fruits.txt file and view its content. ππ.
to create:
touch <file_name>
to view:
cat <file_name>
π Add content to the file βοΈπ.
- In fruits.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava.
To add content, we use the editor. I will use the vim editor.
To activate the vim editor use vim <file_name>
.
Note :- To activate the insertion mode press "i" of your keyboard and to save the work press esc + : + wq
w for the write and
q for quit.
π Display the specific line in the file.
Display only the top three fruits from the file ππ₯π.
head -n <file_name>
"n" denotes how many lines you have to display.
- To Show only the bottom three fruits from the file π₯ππ.
π Create a Colors.txt file and view its content. π¨π
to create:-
touch <file_name>
to view:-
cat <file_name>
π Add the following content to the Colors.txt file (one color per line)
π Find the difference between the contents of the fruits.txt and Colors.txt files. ππ¨
diff file1.txt file2.txt