Linux is an operating system that many developers will use.
Therefore, it’s a good idea to learn some Linux commands.
In this article, we’ll look at some useful Linux commands we should know.
wc command lets us count lines, words, or bytes.
For instance, we run:
wc -l test.txt
to count the number of lines in
We count the number of words in the file with:
wc -w test.txt
And we tet the number of bytes in the file with:
wc -c test.txt
-m flag gets the correct byte value.
open command lets us open files, directories, and programs.
to open a file.
It also works with directory.
We can open the current directory with:
passwd command lets us change a user’s password.
We run it to get a prompt to enter the current password and the new password we want to set.
We can also run:
passwd <username> <new password>
to set a user’s password when we’re logged in as a superuser.
chmod lets us change file permissions.
To change it, we run
chmod with the following letters:
astands for all
ustands for user
gstands for group
ostands for others
Then we type in
+ to add a permission or
- to remove it.
Then we enter one or more permission symbols:
For instance, we run:
chmod a+r filename
to add the read permission to
filename for all users.
We can add permissions for multiple roles by adding multiple letters before the
chmod og-r filename
Now we remove the read permission to
filename for other and group.
We can apply permissions recursively with the
We can also set file permissions with numbers.
It can be one of the following:
3can write, execute
5can read, execute
6can read, write
7can read, write and execute
Then we run:
chmod 777 filename
We set the permission for user, group, and others with the digits.
7 is created by adding 1, 2, and 4 together.
This gives everyone full permission to work with
We can change the owner of a file or directory with the
The general format is:
chown <owner> <file>
Then we can change the permission by running:
chown user test.txt
We change the owner of
Also, we can change the permission of all files and directories recursively with the
chown -R <owner> <file>
Or we can change the owner to a group with:
chown <owner>:<group> <file>
So we can run:
chown bob:users test.txt
to change the owner to
bob in the
users group for
We can also change the group of a file with the
chgrp <group> <filename>
We can change file permissions, count file sizes, and change passwords with some Linux commands.