Find a File: find
Example usage: find /location/ -name <file>
This command can help you locate files on your disk. Follow the find
command with the location of the directory that you want to search in, the -name
flag, and then the name of the file that you want to find.
You can always use a wildcard *
to search partial filenames. For example, find /location/ -name '*.png'
would find all files with the .PNG extension in the specified location.
Open a File: open
Example usage: open <file>
You can use the open
command to open files or directories simply by specifying the path or path with filename thereafter. Open multiple directories or files by chaining them at the end of the command. For example, open file1.txt file2.txt file3.txt
.
You can also open files in specific applications using the -a flag, followed by the name of the application (or the path to the .APP file if you know it). For example: open -a Preview file.pdf
.
Edit a File: nano
Example usage: nano <file>
nano is a basic open-source text editor included with macOS for editing files within the Terminal. You can edit text-based files, including system files, using the nano
command, followed by the filename.
Once you’re in nano, pay attention to the commands at the bottom of the screen, which involve the control key. To save a file, hit Control+O (known as “Write Out”) or quit without saving using Control+X.
Run as Super User: sudo
Example usage: sudo <command>
The sudo
prefix is used to execute a command as a “super user,” also known as root or admin. Once you’ve entered a command prefixed by sudo
, you’ll be required to enter your administrator password to execute it.
Some commands require root access in order to work. If you want to edit a system file, for example, you might need to use sudo nano <file>
in order to save your changes.
Show the Working Directory: pwd
Example usage: pwd
To display the current directory that you’re in (or “print working directory”), you can use the pwd
command. This is especially useful for printing a path that you can later copy and paste.
Show Running Processes: top
Example usage: top
To see a list of currently running processes and how much CPU and memory they’re currently using, execute top
. By default, the process will display all processes by CPU usage, with the process id or PID
displayed alongside each entry.
You can hit “Q” to get back to the command line when you’re done.
Terminate a Process: kill
Example usage: kill <PID>
To kill a process, you’ll first need to run the top command to find its process ID (or PID
). You can then use the kill
command, followed by the number displayed alongside the process. For example: kill 1569
.
Learn More about a Command: man
Example usage: man <command>
Each command on this list has a manual associated with it that explains exactly how to use it and what the different flags do, along with some more exotic examples of the commands being used.
For example, the top
command has a lot of flags and other modifiers, which you can read about using: man top
. If you want to master the command line, use of the man
command is vital.
No comments:
Post a Comment