bash-tutorial/tutorial/files_directories.org

98 lines
1.5 KiB
Org Mode
Raw Normal View History

2022-07-18 14:23:28 +02:00
#+options: toc:nil num:nil author:nil
2022-07-03 21:06:29 +02:00
* Files and directories
** Create empty file
Create "file.txt" with command ~touch~
: touch file.txt
Create a file redirecting the shell output using "~>~" operator
: echo I will put this text wthin a file > file2.txt
** List files
Use ~ls~ in the directory you want to explore
: ls
List with properties using options ~-l~ and ~-la~
: ls -l
: ls -la
List using wildcards
List all files ending in ".csv"
: ls *.csv
List all files containing the characters "moda" within name, e.g.,
"acomoda", "comoda.txt"...
: ls *moda*
Remove "x"
: rm x
Copy a file using "~cp~ source destination"
: cp /home/text.csv /home/myuser/text.csv
Copy multiple files, directories or disk using "rsync" (source, destination).
The command accepts arguments:
- "-r" recursive
- "-v" verbose
- "-a" archive (keeps info about files)
: rsync -rav /home/user/Documents /run/media/user/disk/backup/
~rsync~ can be also used with selective copyng based on file type
: rsync /home/user/Desktop/*.jpg /home/user/Desktop/backupdata/
Create directory
: mkdir new_dir
Remove (unlink) a directory
Some arguments:
* -r: recursively unlink
* -v: verbose
* -f: force
: rm -r new_dir
Remove a file
: rm file.txt
Space used by a directory
: du -hs /usr
Display directory
: pwd
Change directory you are working from terminal.
Go to the home of the user
: cd
Go one level up in the directory tree
: cd ..
Go to "Documents" directory
: cd /home/myuser/Documents