User Tools

Site Tools


os_cp:files_processes

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
os_cp:files_processes [2024/03/05 14:51]
jkonczak [Hard and soft links]
os_cp:files_processes [2025/03/12 21:03] (current)
jkonczak
Line 1: Line 1:
 ===== Copying, moving and erasing files ===== ===== Copying, moving and erasing files =====
  
-<​html>​<small></​html>+<​small>​
  
-To create an empty file, you can use ''​touch //​file//''​. To create file with some contents, you can use ''​echo //​contents//​ > //​file//''​ or ''​fortune > //​file//''​.+To create an empty file, you can use ''​touch //​file//''​. 
 +To create file with some contents, you can use ''​echo //​contents//​ > //​file//''​ 
 +or ''​fortune > //​file//''​.
 \\ \\
 The ''​touch''​ and ''​echo''​ commands as well as meaning of ''>''​ will be explained later on. The ''​touch''​ and ''​echo''​ commands as well as meaning of ''>''​ will be explained later on.
Line 11: Line 13:
 To display a file, use ''​cat //​filename//''​. To display a file, use ''​cat //​filename//''​.
  
-<​html>​</small></​html>+</​small>​
  
 ==== Directories ==== ==== Directories ====
Line 17: Line 19:
 **''​mkdir //​dir//''​** creates a new directory. **''​mkdir //​dir//''​** creates a new directory.
 \\ \\
-<​html>​<small></​html>+<​small>​
 ''​mkdir -p //​dir1/​dir2/​dir3//''​ creates directory ''​dir1'',​ and directory ''​dir2''​ within ''​dir1'',​ and ''​dir3''​ within ''​dir1/​dir2''​. ''​mkdir -p //​dir1/​dir2/​dir3//''​ creates directory ''​dir1'',​ and directory ''​dir2''​ within ''​dir1'',​ and ''​dir3''​ within ''​dir1/​dir2''​.
 \\ \\
 With the ''​-p''​ switch ''​mkdir''​ does not print an error if a directory already exists. With the ''​-p''​ switch ''​mkdir''​ does not print an error if a directory already exists.
-<​html>​</small></​html>+</​small>​
  
 To remove an empty directory one can use ''​rmdir //​dir//''​. To remove an empty directory one can use ''​rmdir //​dir//''​.
  
 ~~Exercise.#​~~ Create the following directory tree: ~~Exercise.#​~~ Create the following directory tree:
 +<​html><​pre style="​margin-top:​-1.2em">​
   .   .
   ├── foo   ├── foo
Line 33: Line 36:
   └── foobaz   └── foobaz
       └── bar       └── bar
- +</​pre></​html>​ 
 ~~Exercise.#​~~ Remove ''​foo/​baz''​ directory ~~Exercise.#​~~ Remove ''​foo/​baz''​ directory
  
Line 48: Line 52:
 ~~Exercise.#​~~ Create a file ''​file1''​ with some contents. Create a hard link called ''​file2''​ of the file ''​file1''​. Modify ''​file2''​. Display ''​file1''​. ~~Exercise.#​~~ Create a file ''​file1''​ with some contents. Create a hard link called ''​file2''​ of the file ''​file1''​. Modify ''​file2''​. Display ''​file1''​.
  
-<​html>​<small></​html>+<​small>​
  
 ~~Exercise.#​~~ The ''​ls''​ command can display link count for each listed file. Discover how to do it. ~~Exercise.#​~~ The ''​ls''​ command can display link count for each listed file. Discover how to do it.
Line 54: Line 58:
 The disk space used by a file is reclamied once link count drops to 0 (all directory entries that link to the file are erased) and the file is no longer open in any process. The disk space used by a file is reclamied once link count drops to 0 (all directory entries that link to the file are erased) and the file is no longer open in any process.
  
-<​html>​</small></​html>+</​small>​
  
 ~~Exercise.#​~~ Create in your home directory a symlink called ''​TMP''​ pointing to ''/​tmp''​. Change directory to ''​TMP''​. What does ''​pwd''​ output? ~~Exercise.#​~~ Create in your home directory a symlink called ''​TMP''​ pointing to ''/​tmp''​. Change directory to ''​TMP''​. What does ''​pwd''​ output?
Line 62: Line 66:
 ~~Exercise.#​~~ Create a symlink to a non-existent path. List the directory containing it. ~~Exercise.#​~~ Create a symlink to a non-existent path. List the directory containing it.
  
-<​html>​<small></​html>+<​small>​
  
-The ''​readlink [-f] //​target//'' ​command resolves ​all symlinks and prints ​a [[https://​en.wikipedia.org/​wiki/​Canonicalization|canonical]] path.+The commands ​''​readlink [-f] //​target//'' ​and ''​realpath -e //​target//''​ resolve ​all 
 +symlinks and print a [[https://​en.wikipedia.org/​wiki/​Canonicalization|canonical]] path.
  
 The Windows NTFS filesystem supports links as well. Creating the links is possible e.g., with [[https://​learn.microsoft.com/​en-us/​windows-server/​administration/​windows-commands/​mklink|mklink]] command. The Windows NTFS filesystem supports links as well. Creating the links is possible e.g., with [[https://​learn.microsoft.com/​en-us/​windows-server/​administration/​windows-commands/​mklink|mklink]] command.
  
-<​html>​</small></​html>+</​small>​
  
 ==== Copying and moving files ==== ==== Copying and moving files ====
Line 78: Line 83:
 The basic syntax is ''​cp/​mv //​source//​… //​destination//''​. \\ The basic syntax is ''​cp/​mv //​source//​… //​destination//''​. \\
 Multiple source files can be provided if the destination is a directory. \\ Multiple source files can be provided if the destination is a directory. \\
-If the destination is a file, it will be overwritten without warning ​<​html>​<small></​html>(unless ''​-i''​ or ''​-n''​ switch is used)<​html>​</small></​html>.+If the destination is a file, it will be overwritten without warning <​small>​(unless ''​-i''​ or ''​-n''​ switch is used)</​small>​.
  
-<​html>​<small></​html>+<​small>​
  
 By default ''​cp''​ will deny copying a directory. Use ''​-r''​ to copy a directory recursively. By default ''​cp''​ will deny copying a directory. Use ''​-r''​ to copy a directory recursively.
  
-<​html>​</small></​html>+</​small>​
  
 When ''​cp''​ copies a file, it creates a new file with the current date, default permissions,​ etc. When ''​cp''​ copies a file, it creates a new file with the current date, default permissions,​ etc.
Line 90: Line 95:
 To copy recursively,​ and preserve dates, permissions and more, one can use the **''​-a''​** switch (that stands for ''​--archive''​). To copy recursively,​ and preserve dates, permissions and more, one can use the **''​-a''​** switch (that stands for ''​--archive''​).
  
-<​html>​<small></​html>+<​small>​
  
 With the ''​-l''​ switch ''​cp''​ creates a hard link instead of copying a file. Notice that this can be combined with ''​--recursive''​. With the ''​-l''​ switch ''​cp''​ creates a hard link instead of copying a file. Notice that this can be combined with ''​--recursive''​.
  
-<​html>​</small></​html>+</​small>​
  
 ~~Exercise.#​~~ Copy, using a single command, the files ''/​​etc/​​os-release''​​ and ''/​​etc/​​SUSE-brand''​​ to the current working directory. ~~Exercise.#​~~ Copy, using a single command, the files ''/​​etc/​​os-release''​​ and ''/​​etc/​​SUSE-brand''​​ to the current working directory.
Line 106: Line 111:
 ~~Exercise.#​~~ Rename ''​someDir''​ to a name of your choice. ~~Exercise.#​~~ Rename ''​someDir''​ to a name of your choice.
  
-<​html>​<small></​html>+<​small>​
  
-~~Exercise.#​~~ Copy the renamed directory with ''​-al''​ switches. Modify a selected file with any of the directories. Which files changed contents? ​<​html><​small></​html> ​\\ (You can ''​cat //​filename//''​ or display modification dates with second accuracy using ''​ls -l --time-style=+%H:​%M:​%S …''​ or ''​tree -D --timefmt=%H:​%M:​%S …''​)<​html>​</small></​html>+~~Exercise.#​~~ Copy the renamed directory with ''​-al''​ switches. Modify a selected file with any of the directories. Which files changed contents? 
 +\\ (You can ''​cat //​filename//''​ or display modification dates with second accuracy using ''​ls -l --time-style=+%H:​%M:​%S …''​ or ''​tree -D --timefmt=%H:​%M:​%S …''​) 
 + 
 +</​small>​
  
 === [extra] Copying files to/from a remote machine === === [extra] Copying files to/from a remote machine ===
Line 116: Line 124:
 ''​scp''​ accepts the ''​-r''​ switch for copying recursively. ''​scp''​ accepts the ''​-r''​ switch for copying recursively.
  
-<​html>​<small></​html>+<​small>​
  
 Microsoft Windows now ships with ''​scp''​ command, but usually [[https://​en.wikipedia.org/​wiki/​Comparison_of_FTP_client_software#​Protocol_support|various file commanders]] are more convenient. Microsoft Windows now ships with ''​scp''​ command, but usually [[https://​en.wikipedia.org/​wiki/​Comparison_of_FTP_client_software#​Protocol_support|various file commanders]] are more convenient.
  
-<​html>​</small></​html>+</​small>​
  
 Most SSH servers enable also the SFTP protocol that allows copying files more conveniently.\\ Most SSH servers enable also the SFTP protocol that allows copying files more conveniently.\\
Line 131: Line 139:
 ~~Exercise.#​~~ Copy the file to ''/​tmp''​ directory on another computer using ''​sftp''​. ~~Exercise.#​~~ Copy the file to ''/​tmp''​ directory on another computer using ''​sftp''​.
  
-<​html><​small></​html>​ 
-=== Rsync === 
  
-The ''​[[https://​en.wikipedia.org/​wiki/​Rsync|rsync]]''​ program is widely used to copy files and directories. It efficiently compares source files with destination files and copies only the differences. It can copy data to/from remote machines, and can compress the data sent via network to increase throughput. ''​rsync''​ is also commonly used to make backups.+=== [extra] ​Rsync ===
  
-<​html><​/small><​/html>+The ''​[[https:​//en.wikipedia.org/​wiki/​Rsync|rsync]]''​ program is widely used to copy files and directories. It efficiently compares source files with destination files and copies only the differences. It can copy data to/from remote machines, and can compress the data sent via network to increase throughput. ''​rsync''​ is also commonly used to make backups.
  
-<​html></​small></​html>​ 
  
 ==== Removing files ==== ==== Removing files ====
Line 180: Line 185:
  
 ~~Exercise.#​~~ Measure how long it took to execute the command in the previous example. ~~Exercise.#​~~ Measure how long it took to execute the command in the previous example.
- 
  
 <​small>​ <​small>​
 +
 ~~Exercise.#​~~ Tell how long it takes to execute the ''​openssl dhparam -text 1536''​ command. ~~Exercise.#​~~ Tell how long it takes to execute the ''​openssl dhparam -text 1536''​ command.
  
 ~~Exercise.#​~~ Run the ''​openssl dhparam -text 2048''​ command with 5s run limit. ~~Exercise.#​~~ Run the ''​openssl dhparam -text 2048''​ command with 5s run limit.
 +
 </​small>​ </​small>​
  
Line 237: Line 243:
 </​small>​ </​small>​
  
-==== Getting information on currently ​run processes ====+==== Getting information on currently ​running ​processes ====
  
 === List of processes === === List of processes ===
Line 250: Line 256:
  
 <​small>​ <​small>​
 +
 The ''​ps''​ program has two allowed command syntaxes — one typical for UNIX programs, one with its roots in BSD. The ''​ps''​ program has two allowed command syntaxes — one typical for UNIX programs, one with its roots in BSD.
 \\ \\
 The ubiquitous ''​ps aux''​ command is an example of ''​ps''​ run with BSD-style options The ubiquitous ''​ps aux''​ command is an example of ''​ps''​ run with BSD-style options
 that show all processes in a specific format. that show all processes in a specific format.
 +
 </​small>​ </​small>​
  
Line 306: Line 314:
 </​small>​ </​small>​
  
-<​html><​small></​html>​ 
  
 === [extra] Live process viewers === === [extra] Live process viewers ===
Line 341: Line 348:
 There are numerous ''​top''​-inspired programs. These include ''​iotop''​ (for I/O), There are numerous ''​top''​-inspired programs. These include ''​iotop''​ (for I/O),
 ''​atop''​ and ''​glances''​. ''​atop''​ and ''​glances''​.
- 
-<​html></​small></​html>​ 
  
 === Looking up process identifiers === === Looking up process identifiers ===
Line 357: Line 362:
 The ''​pidof //​name//''​ command outputs pids of processes whose executable name (trimmed to 15 characters) The ''​pidof //​name//''​ command outputs pids of processes whose executable name (trimmed to 15 characters)
 is identical to the provided name. is identical to the provided name.
 +
 </​small>​ </​small>​
  
Line 374: Line 380:
 role for processes as interrupts do for the operating system — they notify role for processes as interrupts do for the operating system — they notify
 a process about an external event by forcefully switching the control flow of a process about an external event by forcefully switching the control flow of
-one of the processes ​threads to a signal handler.+one of the process'​s ​threads to a signal handler.
 \\ \\
 The programmer can choose to block or ignore specified signals and may set up The programmer can choose to block or ignore specified signals and may set up
Line 429: Line 435:
 Switches allow comparing against full executable name, and using regular Switches allow comparing against full executable name, and using regular
 expressions. expressions.
 +
 </​small>​ </​small>​
  
Line 436: Line 443:
  
 <​small>​ <​small>​
 +
 ~~Exercise.#​~~ In one terminal run a DNS server with the ''​named -g -c <​(:​)''​ command. From another terminal send a HUP signal to ''​named''​. How did it react? ~~Exercise.#​~~ In one terminal run a DNS server with the ''​named -g -c <​(:​)''​ command. From another terminal send a HUP signal to ''​named''​. How did it react?
-</​small>​ 
  
-<​html><​small>​</html>+</small>
  
 ==== [extra] Controlling process scheduling ==== ==== [extra] Controlling process scheduling ====
Line 493: Line 500:
 ~~Exercise.#​~~ In two terminals run ''​taskset -pc 0 $$''​ (<​small>​that lets this shell and its children use only first physical thread</​small>​). ~~Exercise.#​~~ In two terminals run ''​taskset -pc 0 $$''​ (<​small>​that lets this shell and its children use only first physical thread</​small>​).
 \\ \\
-Then, in both terminals, run ''​openssl dhparam -text %%$((2**14))%% [//​arbitrary text//]''​+Then, in both terminals, run ''​openssl dhparam -text %%$((2**13))%%''​
 (<​small>​this starts some CPU-intensive computations</​small>​). (<​small>​this starts some CPU-intensive computations</​small>​).
 \\ \\
Line 538: Line 545:
 on physical threads of node //x// and memory of node //y//. on physical threads of node //x// and memory of node //y//.
  
-<​html></​small></​html>​ 
  
  
Line 544: Line 550:
 language = en language = en
 ~~ ~~
- 
- 
os_cp/files_processes.1709646706.txt.gz · Last modified: 2024/03/05 14:51 by jkonczak