Viewing and changing the file system Flashcards
$ ls
Will “list” the files and folders in the current directory/specified directory.
Common Options;
-a list all contents including hidden files.
-l list contents in long format.
long format includes: file permissions, hard links, file owner, group owner, file size, date last modified and file name.
-t order files and folders by the time they were last modified.
$ mkdir
“make directory” takes the name or path of a directory you would like to create.
$ touch
takes the name or path of a new file you would like to create. If the file already exists the modification time stamp will be updated.
$ cat
Takes the name or path of a file and outputs its contents to the terminal.
$cp
The cp command takes the name or path of a file and copies it from one destination to another.
command format:
$ cp source.txt destination.txt
Wildcards
A wildcard is a special character used to represent one or more characters in a search pattern.
In addition to using exact filenames as arguments, we can use special characters like * to select groups of files.
cp examples:
cp * my_directory/
This will copy all files in the working directory to my_directory.
cp *.txt my_directory/
To copy just the ‘.txt’ files you can use a wild card with a suffix:
cp w*.txt my_directory/
Will copy all files that start with w and have a .txt extension.
$mv
“Move” is simular to cp in how it works except the file is not copied it is simply moved.
$mv my_file.txt my_directory/
moving multiple files.
mv my_file_1.txt my_file_2.txt my_directory/
mv can also be used to rename a file.
$mv file_original.txt file_renamed.txt
wildcard example
$mv * school/
mv takes the first argument * to mean all the files in the current directory, and moves them to the destination school/ specified by the second argument.
$rm
The rm command deletes files and directories.
$rm unwanted_file.txt
The -r (recursive) option is used to delete a directory and all of its child directories.
$rm -r unwanted_directory
wildcard
$rm my_directory/*
deletes all the files in the directory.