The command 'pwd' shows you the full path to your current location in the file system. It's like asking, 'Where am I?' and getting a full address.
$ pwd /Users/yourname/Downloads
The command 'mkdir' creates a new folder. You can specify the name of the new folder. If you give a path, it creates the folder there; otherwise, it creates it where you are now.
$ mkdir my-new-folder $ ls Documents my-new-folder
The command 'ls' lists all files and folders in the current directory. If you provide a folder name, it lists contents inside that folder.
$ ls Documents Downloads Pictures
The command 'cd' changes your location to a different folder. For example, 'cd folder-name' moves you into a folder, and 'cd ..' moves you up one level.
$ cd Documents $ cd ..
A filesystem is how a computer organizes its files and folders. It’s structured like a tree, with the root at the base and branches representing folders and files.
Root ├── Folder1 │ ├── File1 │ └── File2 └── Folder2
The 'touch' command creates a new, empty file in the current location.
$ touch new-file.txt $ ls new-file.txt
The command line, also known as a terminal, is a text-based interface that allows you to interact with your computer’s operating system by typing commands.
Commands like 'pwd', 'cd', 'ls', and 'mkdir' are useful to navigate and manage files on your computer through the command line interface.
The 'cp' command copies files or folders from one location to another. The format is 'cp source destination'.
$ cp file1.txt backup/file1.txt
Command options modify the behavior of commands. For instance, 'ls -a' shows all files, including hidden ones, in a directory.
$ ls -a . .. .hiddenfile file1.txt
The 'mv' command moves or renames files or folders. For example, 'mv oldname.txt newname.txt' renames a file, and 'mv file.txt folder/' moves it to a different folder.
$ mv document.txt archive/document.txt
The 'rm' command deletes files. To delete folders and their contents, use 'rm -r'. Be careful, as deleted files cannot be easily recovered.
$ rm unwantedfile.txt $ rm -r old-folder
The 'ls' command can be combined with various options to display files in different formats. For example, 'ls -l' shows detailed information about each file.
$ ls -l -rw-r--r-- 1 user user 0 Sep 2 12:34 file.txt
The '>>' command appends the output of a command to the end of a file. For example, 'echo Hello >> file.txt' adds 'Hello' to the end of 'file.txt'.
$ echo "Hello again!" >> greetings.txt
The pipe '|' takes the output of one command and uses it as input for another. For example, 'ls | grep txt' lists all files ending with '.txt'.
$ ls | grep txt file1.txt file2.txt
The '>' symbol redirects the output of a command to a file, overwriting its contents. For example, 'echo Hello > file.txt' will replace all content in 'file.txt' with 'Hello'.
$ echo "New content" > file.txt
The 'cat' command displays the content of one or more files directly to the terminal screen.
$ cat notes.txt
The 'grep' command searches for specific text in files. For example, 'grep error log.txt' will show all lines in 'log.txt' that contain 'error'.
$ grep "error" logfile.txt
The 'grep -i' command searches for text, ignoring case. For example, 'grep -i hello greetings.txt' will find 'Hello', 'HELLO', 'hello', etc.
$ grep -i "hello" greetings.txt
The 'grep -R' command searches through all files in a directory and its subdirectories for a specific text.
$ grep -R "function" /my-project
Redirecting allows you to send the output of commands to files or other commands, making your command line usage more flexible and powerful.
The command line environment refers to the settings and preferences that affect how the terminal behaves, such as shortcuts, greetings, and environment variables.
$ export PATH="/usr/local/bin:$PATH"
The 'env' command lists all environment variables that are currently set in your terminal session. This is useful for debugging and configuring your environment.
$ env HOME=/Users/yourname SHELL=/bin/bash
The 'alias' command allows you to create shortcuts for longer commands. For example, 'alias ll="ls -la"' makes 'll' a shortcut for 'ls -la'.
$ alias ll="ls -la"
Environment variables are used to store information that can be used by multiple commands. For example, 'HOME' stores the path to your home directory.
After making changes to configuration files like ~/.bash_profile, use the 'source' command to apply those changes to the current terminal session.
$ source ~/.bash_profile
The 'history' command displays a list of all commands you’ve entered in the current terminal session. This can be helpful for repeating previous commands.
$ history 1 ls 2 cd Documents 3 mkdir new-folder
The 'export' command makes a variable available to all child sessions of the terminal. This is often used to set environment variables.
$ export USERNAME="yourname"
The 'HOME' variable stores the path to your home directory. You can use it to quickly navigate back to your home directory.
$ cd $HOME
Welcome to our comprehensive collection of programming language cheatsheets! Whether you're a seasoned developer or a beginner, these quick reference guides provide essential tips and key information for all major languages. They focus on core concepts, commands, and functions—designed to enhance your efficiency and productivity.
ManageEngine Site24x7, a leading IT monitoring and observability platform, is committed to equipping developers and IT professionals with the tools and insights needed to excel in their fields.
Monitor your IT infrastructure effortlessly with Site24x7 and get comprehensive insights and ensure smooth operations with 24/7 monitoring.
Sign up now!