Commands to remember in Mac OS and Windows

Posted in windows on January 17, 2023 by Jessica Rose ‐ 9 min read

Commands to remember in Mac OS and Windows

10xer.co Ad Sponsored

ⓘ Sponsored by 10xer.co

How to create an “Alias” for a command

With a simple command, you can create an alias for the command.

Alias for a command in Linux or macOS can be created with the “alias” command in the terminal. Let’s take an example and replicate this :

ls-command

  1. To create an alias for the “ls -la” command
alias ll='ls -la

Please the above command without and press enter.

  1. The above command creates an alias called “ll”, but executes the command “ls -la”.

  2. To use the alias, simply type “ll” in the terminal and press enter.

In Windows, you can use the doskey command in the command prompt.

Let’s take an example and replicate this in windows :

  • ls is used to list, but dir is used to list in windows, in the below example, we are going to replace dir with ls.
  1. Open the terminal and type the below command and press enter:
 doskey ls=dir 
  1. The above command creates an alias called “ls” that runs the “dir” command when entered.

To use the alias, simply type “ls” in the command prompt and press enter.

How to check the history of the command Line?

history-command

The “history” command is a built-in command in Linux and macOS that allows you to view a list of previously executed commands in the current terminal session.

By default,

  1. The “history” command will display the commands in the order they were executed,
  2. With a number assigned to each command, called the command number.

For example,

  1. If you type “history” in the terminal, a list of all commands that are executed in the terminal session will be shown.

  2. The command displays

  • Command number,
  • Time and date of execution.

Options: use the -c option to clear the history list. Now, let’s say you have a command in line number 10 of a history list. It can simply be excuted with

!10

and press enter

Searching through the history list can be done grep command :

history | grep ls

and press enter

The history command is a very useful command for

  1. troubleshooting,
  2. testing and
  3. re-executing the commands that you have previously executed.

How to find the forgotten command line Commands

This is one of the most useful commands, and it saves a lot of time and helps to execute the commands that you have forgotten.

To access previous commands from your command line history:

  • Open a command line window.
  • Press the Ctrl-R keys.
  • Begin typing any part of the command you wish to recall.
  • The command line will display suggestions for commands that match what you’ve typed.
  • Press Enter to execute the suggested command.

If you just want to search your history, you can just use

history | grep ssh

substituting ssh for whatever you want to search.

How do I find the hidden files and folder

To show hidden files and folders in a GUI file explorer on a Windows or macOS, you can use the following steps:

Windows:

  1. Open File Explorer.
  2. Click on the “View” tab.
  3. Check the “Hidden items” checkbox.

Mac OS:

  1. Open Finder.
  2. Press the “Command + Shift + .” keys.
  3. To show hidden files and folders in the command line on Linux or macOS, you can use the following command:
ls -la

This command will display all files and folders, including hidden ones, in the current directory.

Hidden files and directories are denoted by a “.” at the start of the file/folder name.

Note: if you want to permanently show hidden files, you will need to change the settings in your file explorer or use different commands for different file managers.

Copy-Paste Files from one Folder to Another with ditto command

Ditto can be used to copy files from one folder to another :

ditto [original_folder][new_folder]

example :

ditto /user/a/folder /user/b/folder

How to Download Files from the Internet via Command Line

If you prefer to use the command line instead of a browser for downloading a file, keep in mind that the downloaded file will be saved in the current working directory.

To ensure that the file is saved in the desired location, such as the Downloads folder, navigate to that directory before initiating the download.

wget command

wget-command

GNU Wget is a powerful, free tool that allows you to easily retrieve files from the internet using the popular HTTP and FTP protocols.

It can operate in the background, even after you’ve logged off, making it ideal for tasks such as creating mirrors of websites or traversing the web like a search engine robot.

Wget also supports the recursive retrieval of HTML pages and FTP sites, and can even abide by website’s exclusion protocols, such as /robots.txt..

Source: https://gnuwin32.sourceforge.net/packages/wget.htm

wget -r --tries=10 http://fly.srk.fer.hr/ -o log

curl command

curl -O https://www.google.com/

For more option use :

curl --help
Usage: curl [options...] <url>

How to Keep Mac Awake

To disable your Mac from falling asleep, just type:

caffeinate

To stop caffeinating, just type Ctrl + C.

To caffeinate can be set with a timer, as shown below

caffeinate -u -t [num_seconds].

Let’s set the caffeinate timer to 600 seconds(10 mins).

caffeinate -u -t 600
(Naturally, this can be escaped with Ctrl-C too.)

How to repeat Characters by Holding Down a Key

The ability to hold a key and repeat characters is a common feature that many of us are familiar with. For Mac users, this feature can be enabled using the command line by using the following command.

defaults write -g ApplePressAndHoldEnabled -bool FALSE

To revert, run the above command and replace FALSE with TRUE.

How to View Contents of a File Without Opening It

The “cat” command is a built-in command in Linux, macOS and Windows that allows you to view the contents of a text file directly in the terminal. The name “cat” is short for “concatenate,” as the original purpose of the command was to concatenate multiple files together.

To view the contents of a file without opening it, use the “cat” command followed by the file’s path. For example, if you have a Python file named “example.py” in your current directory and you want to check its contents using the command line, you can type:

cat example.py

This will display the contents of the “example.py” file in the terminal, allowing you to quickly and easily view the file’s contents without having to open it in an editor or other program.

Text to speech via Command Line

Use the say “Text to speech” command to make your Mac speak.

For example, to make your Mac

say Hello, World!

run the following command:

How to hide a Specific File or Folder

There are a few ways to hide a specific file or folder in Linux, macOS, and Windows:

  1. In Linux and macOS, you can add a dot (.) at the beginning of the file or folder name to make it hidden. For example, to hide a file named “example.txt,” you would rename it to “.example.txt.” Hidden files and folders are not shown by default in the file manager, but you can still access them by typing their name in the file manager’s location bar or by using the ls -a command in the terminal.

  2. In Windows, you can use the “attrib” command in the Command Prompt to make a file or folder hidden. To hide a file or folder, open the Command Prompt and navigate to the folder containing the file or folder. Then, use the command attrib +h [file or folder name]. To make the file visible again, use the command attrib -h [file or folder name]

  3. In Windows, you can also use File Explorer to hide a file or folder. Right-click the file or folder you want to hide, select Properties and then check the “Hidden” option. You can also use this method to unhide the file or folder by unchecking the “Hidden” option.

Using commands:

To hide a particular secret file or a folder, use this command:

chflags hidden [path_of_the_folder]

to revert back:

chflags nohidden [path_of_the_folder]

To hide a folder :

chflags hidden ~/Desktop/folder

Command Line ASCII Art

ASCII art is a form of digital art that uses characters from the ASCII (American Standard Code for Information Interchange) character set to create images. These images can be created using various tools, including command-line tools.

One such command-line tool that can be used to create ASCII art is “figlet”.

  1. Figlet is a program that creates large characters made up of ordinary screen characters.

To install figlet on Linux and macOS, you can use the package manager, for example, on Ubuntu:

sudo apt install figlet
  1. On Windows, you can download the figlet executable from the official website and add it to your system path.

Once you have figlet installed, you can create ASCII art by typing a command such as:

figlet "your text"

You can also use additional options to change the font and formatting of the text.

Another command line tool that can be used to create ASCII art is “toilet”. Toilet is a similar program that can be used to create large characters made up of ordinary screen characters.

You can install toilet on Linux and macOS by using package manager.

sudo apt install toilet

To create ASCII art using toilet, type a command such as:

toilet "your text"

You can also use additional options to change the font and formatting of the text.

These command-line tools are a fun way to create ASCII art and can be used to create banners, signs, and other text-based graphics. You can also use them to create ASCII art from images or videos by using an image to ASCII converter or video-to-ASCII converter.

To display ASCII art text, use this syntax:

banner -w [banner_width][banner_text]

For example : 

banner -w 50 Elon Musk

How to check for macOS Updates More Frequently

apple-update

To modify the update check frequency on your Mac from weekly to daily, use the following command in the terminal:

defaults write com.apple.SoftwareUpdate ScheduleFrequency -int 1

This will change the setting for macOS updates to check for updates on a daily basis.

how to list the Contents of a Folder and Its Subfolders

ls-command

The “ls” command is a commonly used command in Linux and macOS that allows you to view the contents of a directory. But, did you know that by adding the “-R” option, you can also view the contents of all the subfolders within that directory?

For example, if you are in a directory called “example” and the contents of all the subfolders within it, you can use the following command:

ls -R example

The above command will display the contents of the “example” directory and all of its subfolders, recursively.

This can be especially useful when you need to navigate through a directory structure with many subfolders and you want to view the content of all the subfolders at once.

Additionally, you can also use other options like -l to view the details like :

  1. Permissions,
  2. File owner,
  3. Size, etc of the files and folders.
  • -a to view the hidden files and folders and
  • -t to sort the files based on the time of modification.

The ls command with the -R option is a powerful tool that can save you time and effort when working with large directory structures.

Thank you for your time. Have a great Day ahead!


10xer.co Ad Sponsored

ⓘ Sponsored by 10xer.co