This document is a guide for information related to Files and Folders. All the Command lines will be provided here with the explanation plus the example.
Knowing how to create a new file is an important skill for anyone using open-source regularly. You can create a new file either from the
command line or from the
desktop file manager.
touch command allows us to update the timestamps on existing files and directories as well as creating, empty files. The only easiest and most memorable way to create new, empty files is by using the
To create a new file simply run the touch command followed by the name of the file you want to create:
You can also create multiple files at once by specifying the file names separated by space.
touch File_Name1.txt File_Name2.txt File_Name3.txt
.txt stand for the text file. You can also use other extensions for the kind of files you want to use.
echo can also use to create file too. The
echo command prints the strings that are passed as arguments to the standard output, which can be redirected to a file.
echo "some line" >> File_Name.txt
echo $null >> sample.txt
$null here is standing for no. It means there will be no arguments redirected into the file.
Deleting File is one of the frequently done operation. Run
rm command with the name of the file you want to remove:
Here is an example
Display File Content
Cat(concatenate) command is very frequently used in open-source. It reads data from the file and gives their content as output. It helps us to create, view, concatenate files. So let us see some frequently used cat commands.
Edit Text File
There are many ways to edit files through command line such as vi, emacs, pico, ed, and nano. Among those only Nano is regularly using.
Sometimes, we need to add
sudo; which stand for superuser do, in front of it to edit.
sudo nano File_Name
Copy File or Folder
A basic example of the cp command to copy files (keep the original file and make a duplicate of it) might look like:
cp File_Name NewFile_Name
If you want to copy other file from one directory to other directory, you can use the command below:
cp -R <source_folder> <destination_folder>
-i for interactive, asks you to confirm if an existing file (perhaps a version of joe_expenses already exists in the cashflow directory) should be overwritten in the copying process.
-r for recursive, to copy all the subdirectories and files in a given directory and preserve the tree structure.
-v for verbose, shows files being copied one by one.
Move/Rename file or folder
For instance, to instantly seek out and move all of the folder. Your command-line instruction would simply be:
mv Folder_Name NewFolder_Name
we can create directories from command line using the command
mkdir. Syntax of this command is explained below.
For example, to create a folder named ‘newfolder‘ the command is:
Removing folder is like removing the file, too but it has a little bit different. You have to add
rm -r Folder_Name
List Folder Contents
Listing Command (ls) allows us to see all the contents in the directory we are in.
For more info use
--help after the command like this `ls –help``.
Change Folder or Directory
cd is the command for changing the folder/directory of the command line. Here its syntax:
Changing to home directory (determined by $HOME environment variable):
Also change to home directory:
Change to parent directory:
Change to subdirectory Documents:
Change to directory with absolute path
Change to directory name with white space -path Name
cd path\ Name
\ here is stand for white space !!!
Show Current Folder
To show the directory you are currently in:
Create Physical Link to File or Folder
To make links between files you need to use
ln command. A symbolic link (also known as a soft link or symlink) consists of a special type of file that serves as a reference to another file or directory.
ln [FileName] [LinkName]
Find Phrase Within File
The grep command is used to search text. It searches the given file for lines containing a match to the given strings or words. It is one of the most useful commands.
Below is some standard grep command explained with examples to get you started with grep. Search any line that contains the word in filename.
grep 'Strings' FileName
Perform a case-insensitive search for the word:
grep -i 'Strings' FileName
Looking for all files in the current directory and in all of its subdirectories.
grep -R 'Strings'
Searching and displaying the total number of times that the string appears in FileName.
grep -c 'Strings' FileName
Searching by paths:
grep 'Strings' path/path/path
You can mount the filesystem with the syntax below:
mount /dev/[device] [path]
You can also unmount filesystem with command below.
Make File Executable
Change the rights to a file so that it can run as a program.
chmod +x filename
List Trash Files
As you have already known what is
ls command, you should know the path of the trash file.
ls -l files ~/.local/share/Trash/files
Above are the paths of trash file, we can empty it with
rm -r command:
rm -r ~/.locale/share/Trash