Working with files and filesystems
Basic file redirection:
>
: Redirect to a file<
: Take input from a file|
: Send output to another program>>
: append to an existing file- use
tee
to display output but also write it to a file:- example:
ls | tee outfile.txt
- example:
Examples:
date > test.md # Create a file called "test.md" with the current date
date >> test.md # Append the date to an existing file "test.md"
date | grep Fri # Look for a string "Fri" in the output of date
sort < test.md # Sort the contents of test.md
Other ways of working with files:
du
anddf
: show directory and disk usagetree
: list directory contents in a tree-like formatmc
: (Midnight Commander) visual shell
Apart from typing commands to view the structure and contents of the filesystem, it is also possible to visually interact with directories of files using tools like Midnight Commander.
Midnight Commander can be accessed using the mc
command, which opens up a split view of the current directory. Both panes of this view can be configured to view different locations in your filesystem, or to perform other operations like viewing files.
Midnight Commander basics:
F9
: Access menuAlt+.
: Hide hidden files and directoriesF5
: Copy files from one pane to the otherF6
: Rename/move filesF7
: Make new directory+
and-
to select files,*
to invert selectionAlt+C
: Quick change directory