Common Operations via Command Line for Mac Os X - ByteScout
  • Home
  • /
  • Blog
  • /
  • Common Operations via Command Line for Mac Os X

Common Operations via Command Line for Mac Os X

For many users, the Mac’s OS X is one amazing user interface but for security researchers, programmers, and system administrators Mac’s command-line interface is an important weapon and, in many instances, the only way to achieve specific tasks. Here is the list of some common operations via the command line for Mac Os X.

Here’s the list of commands with examples that might be a great cheat sheet for any user:

  1. locate
  2. lsof
  3. networksetup
  4. open
  5. mkdir
  6. history
  7. cat
  8. shutdown
  9. top

Common Operations via Command Line for Mac Os X


The locate utility hunts a particular private database of all open pathnames that OS X keeps individually from the searchable index. It’s very quick to explore, but the database is restored only systematically — almost daily. The locate command is extremely beneficial if users are looking to find every occurrence of a file buried deep-toned in system folders or anything else that Spotlight can’t control. It’s extraordinarily helpful for troubleshooting and even more ordinary jobs like uninstalling Mac apps.

locate *.png

The above command will locate all the png files.


The lsof is the list open files command. When hunting down difficulties, especially security-related problems, it’s usually necessary to identify which applications are actually interacting on the network. The lsof command is responsible for finding that. With the -i option, it gives all the public network connections in the process and the signatures of the applications utilizing them. This is one of the most useful commands.

$ lsof -i

The above command will list all the files.


Network troubleshooting usually demands analyzing a machine’s network environments and perhaps making adjustments to them to examine different assumptions about what may be faulty. The networksetup tool allows users to inspect all methods of network parameters such as IP addresses, possible network interfaces, and more than 50 other parameters. One configuration users apparently have to check regularly is the record of DNS servers, particularly in circumstances of the contemporary malware that modified this list to show to malicious DNS servers.

$ networksetup -getdnsservers ethernet


One of OS X’s most handy operations, open helps soft communication between a command-line and the user interface. From the command line, users can open a folder or directory into a Finder, and then they can also open a text file or a document to make some quick changes.

$ open FaceTime

The above command can also be used to open various other applications for editing purposes.


mkdir means “Make Directory” or just, create a new folder. Anywhere this command is shot from, it will build the new folder in that drive. In this, users can define the title of the directory (folder) they desire to build or create. For example, the following command will create a folder called my-folder. This command is one of the most important and most used commands.

mkdir my-folder

As mentioned earlier, the above command example will create a new directory called my-folder. The important thing about this command is that users can create a series of directories and subdirectories forever if they want, In this, simply type out the path and press enter.


Viewing the command history could be a helpful trait if users want to examine a long-drawn command they’ve applied recently. The history command makes it straightforward to just copy and paste the command and recycle it. Understanding the command history can also be beneficial if there are many other users on the Mac and if a user needs to understand what sorts of operations they’re executing with the Terminal app. To execute this command simply enter history and press the return key.


The cat command is also known as concatenating is one of the most commonly applied commands Mac OS X and various other operating systems. cat command enables users to build single or various files, view checks of a file, concatenate files, and redirect results in files. For example, if you want to concatenate two files, creating the result to be a single file then this can be done by using the following command:

$ cat Myfile100.txt MyfFile200.txt > union.txt

The above command will concatenate the two files.


System programmers or administrators occasionally have to reboot machines when the administrator isn’t nearby. Giving the screen isn’t invariably helpful — or even allowed. If users can get exclusive command-line access to the destination machine such as by the ssh or Secure Shell command, restarting remotely is a setup utilizing the shutdown command. The -r alternative means the user needs to restart; without it, the Mac will shut down. The now argument suggests exactly what it states: shutdown it now. Users can also define a date and time, in a pattern like yymmddhhmm, to preconfigure or reset a prolonged reboot.

$ shutdown -r now

The above command will reboot the system now.


The top command is close to Linux users too. It gives the most active programs running on a machine, supporting users to find why a machine might be working moderately. Apple’s graphical Activity Monitor does the related task, but the top command provides the user a smart aspect without neglecting the command-line setting.

By default, the top showcases the initial 20 programs in its inventory. The difficulty is that, for some purpose, OS X’s top classifies its program not in order of decreasing CPU usage but an order of decreasing process ID. To obtain the list in decent CPU usage position users can add the -o cpu) option. The top inventory also reveals which programs are working and which are “flagging” — expecting input/output actions to close. When a system is idle, the top normally exposes the offender.

$ top -o cpu

The above command will display the top 20 programs.


About the Author

ByteScout Team ByteScout Team of Writers ByteScout has a team of professional writers proficient in different technical topics. We select the best writers to cover interesting and trending topics for our readers. We love developers and we hope our articles help you learn about programming and programmers.