bash-tutorial/tutorial/files_directories.org

117 lines
1.5 KiB
Org Mode
Raw Permalink 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~
2023-02-05 23:21:52 +01:00
#+begin_src sh
touch file.txt
#+end_src
2022-07-03 21:06:29 +02:00
Create a file redirecting the shell output using "~>~" operator
2023-02-05 23:21:52 +01:00
#+begin_src sh
echo "I will put this text wthin a file" > file2.txt
#+end_src
2022-07-03 21:06:29 +02:00
** List files
Use ~ls~ in the directory you want to explore
2023-02-05 23:21:52 +01:00
#+begin_src sh
ls
#+end_src
2022-07-03 21:06:29 +02:00
List with properties using options ~-l~ and ~-la~
2023-02-05 23:21:52 +01:00
#+begin_src sh
ls -l
ls -la
#+end_src
2022-07-03 21:06:29 +02:00
List using wildcards
List all files ending in ".csv"
2023-02-05 23:21:52 +01:00
#+begin_src sh
ls *.csv
#+end_src
2022-07-03 21:06:29 +02:00
List all files containing the characters "moda" within name, e.g.,
"acomoda", "comoda.txt"...
2023-02-05 23:21:52 +01:00
#+begin_src sh
ls *moda*
#+end_src
2022-07-03 21:06:29 +02:00
Remove "x"
2023-02-05 23:21:52 +01:00
#+begin_src sh
rm x
#+end_src
2022-07-03 21:06:29 +02:00
Copy a file using "~cp~ source destination"
2023-02-05 23:21:52 +01:00
#+begin_src sh
cp /home/text.csv /home/myuser/text.csv
#+end_src
2022-07-03 21:06:29 +02:00
Create directory
2023-02-05 23:21:52 +01:00
#+begin_src sh
mkdir new_dir
#+end_src
2022-07-03 21:06:29 +02:00
Remove (unlink) a directory
Some arguments:
* -r: recursively unlink
* -v: verbose
* -f: force
2023-02-05 23:21:52 +01:00
#+begin_src sh
rm -r new_dir
#+end_src
2022-07-03 21:06:29 +02:00
Remove a file
2023-02-05 23:21:52 +01:00
#+begin_src sh
rm file.txt
#+end_src
2022-07-03 21:06:29 +02:00
Space used by a directory
2023-02-05 23:21:52 +01:00
#+begin_src sh
du -hs /usr
#+end_src
2022-07-03 21:06:29 +02:00
Display directory
2023-02-05 23:21:52 +01:00
#+begin_src sh
pwd
#+end_src
2022-07-03 21:06:29 +02:00
Change directory you are working from terminal.
Go to the home of the user
2023-02-05 23:21:52 +01:00
#+begin_src sh
cd
#+end_src
2022-07-03 21:06:29 +02:00
Go one level up in the directory tree
2023-02-05 23:21:52 +01:00
#+begin_src sh
cd ..
#+end_src
2022-07-03 21:06:29 +02:00
Go to "Documents" directory
2023-02-05 23:21:52 +01:00
#+begin_src sh
cd /home/myuser/Documents
#+end_src