bash-tutorial/tutorial/files_directories.org

1.5 KiB

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

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