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
teeto 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
File ownership and permissions
To change the user or group of a file, use the chown command:
$ chown user filename
$ chown user:group filename
The chmod command is used to alter the permissions of a file. For example, to add execute permission for the owner of a file:
$ chmod u+x filename
The chmod command does not work the same way on WSL. For a complete guide, see the official Microsoft WSL File Permissions Documentation.
Other ways of working with files:
duanddf: 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
Loading last updated date...