Initial version: 2024-10-08
Last update: 2024-10-08
23. Be aware that telnet is a character-based protocol. Each character you enter on the telnet client will be sent to the server immediately. Therefore, you cannot make typo error in entering your raw command, as delete and backspace will be sent to the server.
telnet command is:
telnet [options] <remote_ip_address> [port]
Running the command without specifying an address opens the telnet interactive mode (to end a session and exit telnet, type quit).
$ telnet 38.76.11.19
22.
ssh [<username>@]<remote_ip_address>
username is optional and you can add it if remote user name is different than local user name.
ssh [<username>@]<remote_ip_address>:<port>
ssh [<username>@]<remote_ip_address> -p <port>
\
|
+-- [boot]
+-- [etc]
+-- [home]
| +-- [fulmanp]
| +-- [classes]
| | +-- notes.pdf
| |
| +-- [documents]
| |
| +-- importantDoc.txt
|
+-- [usr]
+-- [var]
Note that in Linux systems there is slightly different notation of devices like discs or pen-drives. Instead of letters to identify them you have one consistent file system always identified by /. All other devices are represented in this file system as its sub-directories, or being more precisely, as its files because in Linux every device is represented as a file.
notes.pdf file is: /home/fulmanp/classes/notes.pdf. It is different from the relative path fulmanp/classes/notes.pdf which starts at the current directory which is a directory you stoped traversing filesystem. Relative path is transformed into absolute path by concatenating path to the current directory and relative path. For example, if your current directory is /home/fulmanp/documents and it is "joined" with relative path fulmanp/classes/notes.pdf it results in /home/fulmanp/documents/fulmanp/classes/notes.pdf which of course does not correspond to any element in our case.
pwd command allows you to know the current directory name you are in, in other words, it prints (current) working directory.
ls command allows you to display all the files and directories in the current location (directory), in other words, it lists directory. You may ask, why ls instead of more natural ld command? Probably because ld is in use and corresponds to very important piece of software allowing you to create executable files, so called linker.
ls -l
The cd command allows you to change director in Linux, in other words, moves from one directory to another one.
~ – user's home directory;.. – the directory one level up from the current directory (the parent directory of the current directory);. – the current directory;- – the previous directory.') or use the backslash (\) character to escape the space:
'name with space'
name\ with\ space
cd by itself or cd ~ will always put the user in their home directory.cd . will leave the user in the same directory they are currently in (i.e. the current directory won't change).cd ~username will put the user in the username's home directory.cd dir (without a /) will put the user in a subdirectory dir; for example, if you are in /home/fulmanp, typing cd documents will put you in /home/fulmanp/documents.cd .. will move the user up one directory. So, if you are in /home/fulmanp/documents, cd .. moves you to /home/fulmanp, while cd ../.. moves you up two levels, i.e. to /home.cd - will switch the user to the previous directory.file command.
$ touch abc.txt
$ cat > abc.txt [Enter text] [Press Ctrl + D to finish]
$ > abc.txt
$ echo "Hello file" > abc.txt
$ echo 'ab cd
> cd cd ef
> cd ef
> cd ef ef' > abc.txt
cp <source_file> <destination_file>
If you want to copy more than one file from dirA to dirB, you will use the cp command like this:
cp dirA/file.txt dirA/another_file.txt dirB
As you can see, you will put all the source files first, and the last argument will be the destination.
mv. Command:
mv <source> <destination>
moves a source file to the specified destination. For instance:
$ touch example.txt
$ mv example.txt ~/Documents
$ ls ~/Documents
example.txt
You can also rename the file as you move it:
$ touch example.txt
$ mv example.txt ~/Documents/foo.txt
$ ls ~/Documents
foo.txt
It enables you to rename a file even when you don’t want to move it to another location, like so:
$ touch example.txt
$ mv example.txt foo2.txt
$ ls
foo2.txt
Moving a file safely
mv command replaces without any complains the destination file with the one you are moving. This behavior is called clobbering, and in most cases it is exactly what you intend.
--interactive or -i option to ensure that mv asks for confirmation in the event that two files of the same name are in conflict:
$ mv --interactive example.txt ~/Documents
mv: overwrite '~/Documents/example.txt'?
If you do not want to manually intervene, use --no-clobber or -n instead. This flag silently rejects the move action in the event of conflict:
$ mv --no-clobber example.txt ~/Documents
$ ls
example.txt
Moving many files at once
mv treats the final directory name as the destination:
$ mv foo bar baz ~/Documents
$ ls ~/Documents
foo bar baz
$ ls --inode example.txt
7344977 example.txt
When you move a file, you don’t actually move the data from one inode to another, you only assign the file object a new name or file path.
rm filename
Bypassing multiple filenames as arguments to rm, you can delete multiple files:
rm filename1 filename2 filename3
mkdir command
$ mkdir mydir
To create more than one directory simultaneously, specify the names of the new directories after mkdir with a blank space between them:
$ mkdir dir1 dir2 dir3
To create a directory with a directory inside of it, use the -p option:
$ mkdir -p dir4/subdir1
For example, to create a directory called test with default permissions in the /home/fulmanp/nonexisting directory, type the following:
mkdir -p /home/fulmanp/nonexisting/test
The -p results in creating the /home, /home/fulmanp, and /home/fulmanp/nonexisting directories if they do not already exist.
test with rwxr-xr-x permissions type the following:
mkdir -m 755 /home/demo/sub1/Test
cp command works with files. So if you attempt to copy a directory like this:
cp ./directory1/directory2/ ./test
You will get an error stating:
./directory1/directory2/ is a directory
To copy directories, you have to pass the -r flag:
cp -r ./directory1/directory2/ ./test
This flag informs the cp command to recursively copy a directory and its contents (which could be files or other sub directories).
mv command which doesn’t differentiate a file from a directory the way cp does. You use the same syntax:
$ touch foo_file.txt
$ mkdir foo_directory
$ mv foo_file.txt foo_directory
$ mv foo_directory ~/fulmanp/documents
rmdir command:
rmdir doc_to_delete
To remove non-empty directories on use the rm with r flag:
rmdir dir_with_some_content
rm -rf / or rm -rf * command because you will delete the whole system or content of the current directory.
fulmanp, which is Piotr Fulmański) and a certain "type of system operations" (e.g. www user with whom the local www server is associated). From the point of view of the operating system, it is not important who or what the user is. What is important is what resources (files, programs, devices, etc.) belong to which of the users and what they can do with them. Each user is identified by the so-called UID (User ID) which is a number, and the so-called username or login such as fulmanp or www are only aliases for UID that make it easier for people to work in the system. Users can be organized using a superior structure, which is a group. Each user can belong to one or more groups. The existence of groups is justified by the desire to control identical permissions assigned to a certain number of users and related to a selected resource. In such a situation, changing the permissions for a group results in changing the permissions for all users included in the group. Every file in a UNIX-type system is (simultaneously) owned by:
d) they require some explanation:
r – the ability to browse the contents of the directory,w – the ability to change the contents of the directory,x – the ability to enter into the directory (cd command).–. The whole is written as one string. For example, the notation:
rwxr-x--x
means that:
read, write and execute,read and execute,xecute.ls -l is:
$ ls -l
drwxr-xr-x 3 fulmanp fulmanp 4096 2008-01-02 23:23 materials
-rwxr-xr-x 1 fulmanp fulmanp 163 2007-10-14 00:19 preface.tex
-rw-r--r-- 1 fulmanp fulmanp 51024 2007-10-15 14:01 manual.dvi
-rw-r--r-- 1 fulmanp fulmanp 192775 2008-10-07 14:04 manual.pdf
-rwxr-xr-x 1 fulmanp fulmanp 2471 2008-10-06 09:06 manual.tex
drwxr-xr-x 2 fulmanp fulmanp 4096 2008-10-03 11:56 TEST
-rwxr-xr-x 1 fulmanp fulmanp 53065 2008-10-07 16:58 unix.tex
Notice d letter in front of materials and TEST files indicated they are a directory.
chmod commandchmod command. The command syntax is as follows:
chmod [options] permissions file(s)
You define permissions by specifying what you want to do, with what permissions, and for whom. For example, the following entry:
chmod a-x data.txt
means that you delete (the - sign) the x permission from everyone (a means all), i.e. the owner, group, and other people. In general, you have the following symbols at you disposal:
u – denoting the owner,g – denoting the group,o – denoting other users,a – denoting all of the above groups (i.e. the owner, group, and other users).+ – granting a right,- – taking away a right,= – set exactly that right.
$ ls -l
-rw-r--r-- 1 fulmanp fulmanp 0 2008-10-07 17:19 test.txt
$ chmod a-r test.txt
$ ls -l
--w------- 1 fulmanp fulmanp 0 2008-10-07 17:19 test.txt
$ chmod g+rwx test.txt
$ ls -l
--w-rwx--- 1 fulmanp fulmanp 0 2008-10-07 17:19 test.txt
$ chmod g=w test.txt
$ ls -l
--w--w---- 1 fulmanp fulmanp 0 2008-10-07 17:19 test.txt
If you want you can set multiple permissions to multiple classes:
$ chmod ug+rwx example.txt
This grants read, write, and execute for the user and group.
r corresponds to the number 4, the permission w corresponds to 2 and the permission x corresponds to 1. If, for example, you want to set the following rights:
rwxr-x-w-
for the file test.txt, then you specify three numbers as permissions (for each group separately), each of which is the sum of the permissions to be set:
owner group other
rwx r-x -w-
||| | | |
||1 4 1 2
|2
4
sum: 7 5 2
So the command will take the form:
chmod 752 test.txt
SUID is the special permission (s or S) for the user access level and always executes as the user who owns the file, no matter who is passing the command. If the file owner doesn't have execute permissions, then uppercase S is used:
$ ls -l /usr/bin/passwd
-rwsr-xr-x. 1 root root 21245 Oct 13 2024 /usr/bin/passwd
Note the s where x would usually indicate execute permissions for the user.
SGID indicated by (s or S) for the group access level and allows a file to be executed as the group owner of the file. If set on a directory, any files created in the directory will have their group ownership set to that of the directory owner. This is helpful for directories used collaboratively among different members of a group because all members can access and execute new files.
t, where the x would normally indicate the execute privilege.
test.
$ chmod g+s test
Using the numerical method, you need to pass a fourth, preceding digit in the chmod command. The digit used is calculated similarly to the standard permission digits:
SUID = 4
SGID = 2
Sticky = 1
The syntax is:
$ chmod X### file_or_directory
where X is the special permissions digit.
$ chmod 2770 test/
$ ls -ld test/
drwxrws---. 2 fulmanp fulmanp 113 Oct 9 12:10 test/
+ suffix indicates an access control list that can control additional permissions.. suffix indicates an SELinux context is present. Details may be listed with the command ls -Z.@ suffix indicates extended file attributes are present.l prefix mean that it is a symbolic link.
$ ls -l /tmp
lrwxr-xr-x@ 1 root wheel 11 17 lip 12:49 /tmp -> private/tmp
A symbolic link is a special type of file that contains a reference to another file or directory in the form of an absolute or relative path and that affects pathname resolution.
ln -s <target_path> <link_path>
Consider the following example:
$ mkdir -p /tmp/one/two
$ echo "test_a" >/tmp/one/two/a
$ echo "test_b" >/tmp/one/two/b
$ cd /tmp/one/two
$ ls -l
-rw-r--r-- 1 user group 7 Jan 01 10:01 a
-rw-r--r-- 1 user group 7 Jan 01 10:01 b
$ cd /tmp
$ ln -s /tmp/one/two three
$ ls -l three
lrwxrwxrwx 1 user group 12 Jul 22 10:02 /tmp/three -> /tmp/one/two
$ ls -l three/
-rw-r--r-- 1 user group 7 Jan 01 10:01 a
-rw-r--r-- 1 user group 7 Jan 01 10:01 b
$ cd three
$ ls -l
-rw-r--r-- 1 user group 7 Jan 01 10:01 a
-rw-r--r-- 1 user group 7 Jan 01 10:01 b
$ cat a
test_a
$ cat /tmp/one/two/a
test_a
$ echo "test_c" >/tmp/one/two/a
$ cat /tmp/one/two/a
test_c
$ cat a
test_c
root user or a user with sudo can create new groups.
sudo useradd foo_user
To view the groups the current user account is assigned to, run the groups command. You'll see a list of groups:
$ groups
$ sudo groupadd new_group
$ sudo usermod -a -G new_group foo_user
$ grep new_group /etc/group
Add a user to multiple groups:
usermod -a -G group1,group2,group3 user_name
--gid or -g option:
$ sudo groupadd -g 1009 demo1
You can change the group ID of any group with the groupmod command and the --gid or -g option:
$ sudo groupmod -g 1011 demo1
groupmod with the --new-name or -n option:
$ sudo groupmod -n test demo1
usermod command:
usermod -g primarygroup exampleusername
To remove a specific user from a group, you can use the gpasswd command to modify group information:
$ sudo gpasswd --delete user1 demo
groupdel command:
$ sudo groupdel demo
chown command to change ownership. Its syntax is:
chown [options] new_owner[:new_group] file(s)
To change ownership from a specific user (e.g., fulmanp) to another (e.g., root), where the current owner must be master, use the following syntax:
chown --from=fulmanp root foo_dir
This command ensures that ownership is changed from fulmanp to root only when the current owner is fulmanp.
foo_file) onto another file (e.g., bar_file), use the following syntax:
chown --reference=foo_file bar_file
This command copies the ownership details from foo_file to bar_file, ensuring consistency in ownership between the two files.
chgrp command:
chgrp new_group test.txt
As in case of the owner, you use the reference file to change the group of another file or folder:
chgrp -R --reference=ref_file.txt test.txt
To change the group ownership of a file you can also use the chown command:
chown :new_group file1.txt
project to remote system at address 192.168.1.3 as user pi you may use scp command in the following way:
scp -r project/ pi@192.168.1.3:
To get data from remote system at address 192.168.48.3 and directory data of user fulmanp and save them in the current location (.) you may use scp command in the following way:
scp -r fulmanp@192.168.48.3:data/ .
tar command. Its basic structure is as follows:
tar <options> <archive-file> <file or directory to be archived>
For example:
tar -cvzf archive_name.tgz file_or_dir_1 file_or_dir_2
To extract the archive you previously created you may use the following syntax:
tar -zxvf archive_name.tgz