- Linux/Mac
- Windows
Linux/Mac Commands
Navigating the file system:
To change current directory to a directroy called ‘my_directory’. That directory must exist in the current directory.
$ cd my_directory
To change the current directory to a subdirectory called ‘mydir3’. ‘mydir3’ is subdirectory under multiple levels.
$ cd my_dir1/my_dir2/mydir3
To change the current director back out one level.
$ cd/..
To change the current director back out Three level.
$ cd/../../..
To see items in the current directory. Only shows the names of the items.
$ ls
To list the files and directories in more detail. You can tell if an item is a file or a directory. It will also show the owner and size of the items.
$ ls -la
Creating and managing files and directories:
$ mkdir directoryName
$ touch myFile1
To move files to new location
$ mv file ” new file path”
To rename the files to a new fileName
$ mv filename new_file_name
$ cp filename ” new directory path”
$ cp -r name “path”
$ rm filename
$ rm – r name
Viewing and editing files:
$ nano new_filename
$ vim filename.txt
$ cat filename
Searching and filtering:
$ grep [options] pattern [files]
the -i option enables Case insensitive search
$grep -i ‘Word’ filename
$ find [where to start searching from] [expressions determine what to find] [options] [what to find]
To search a file with a specific name
$ find ./GFG -name filename
Permissions and ownership:
To give a read and write permission
$ chomd u = rw new_filename
$ chown [option] [owner] [:[Group]] file
To change owner of a file
$ chown owner_name file_aname
Miscellaneous:
Windows Commands
Navigating the file system:
C:\ > cd dirName
C:\ > pushd [path]
Creating and managing files and directories:
C:\ > mkdir new_folder
To copy file1.txt to file2.txt
C:\ > copy file1.txt file2.txt or
To copy the whole folder with its contents to a new folder
C:\ > copy foldername newfoldername /s
To rename file1.txt to file2.txt
C:\ > move file1.txt file2.txt or ren file1.txt file2.txt
To rename the folder.
C:\ > move foldername newfoldername or ren foldername newfoldername
To delete file1.txt
C:\ > del file1.txt or erase file1.txt
Viewing and editing files:
C:\ > type filename
C:\ > more fileName
C:\ > notepad fileName
Searching and filtering:
To search for “search_string” in file1.txt
C:\ > find “search_string” file1.txt or findstr /s /c:”search_string” file1.txt
To search for files in the directory “C:\Windows” and print their name
C:\ > forfiles /p “C:\Windows” /s /c “cmd /c echo @file”
Permissions and ownership:
To view the permissions of file1.txt
C:\ > cacls file1.txt
To give permission
C:\ > cacls file1.txt /g user1:F
Miscellaneous:
C:\ > cls
C:\ > exit