Overview
ls-h is a custom command that performs the function of 'ls -h', converting file sizes into units like 1024 bytes (K), 1048576 bytes (M), etc., for output. This is very useful for quickly grasping the size of large files or directories.
Key Features
- Displays file sizes in human-readable units (K, M, G)
- Same functionality as the '-h' option of the standard 'ls' command
- Primarily used as a custom alias or script for user convenience
Key Options
Since ls-h itself incorporates the functionality of 'ls -h', it doesn't have separate unique options but can be used in conjunction with other options of the 'ls' command. The options described here are options of the 'ls' command, which can be utilized when ls-h is used as an alias for 'ls -h'.
Display/Format
Generated command:
Try combining the commands.
Description:
`ls-h` Executes the command.
Combine the above options to virtually execute commands with AI.
Usage Examples
Since ls-h is primarily used as an alias for 'ls -h', the examples below demonstrate the usage of 'ls -h'. If the ls-h alias is set up, you can get the same results by typing 'ls-h' instead of 'ls -h'.
Display File Sizes in Current Directory
ls -h
Displays the sizes of files and directories in the current directory in human-readable units.
Display File Sizes with Detailed Information
ls -lh
Displays file sizes in human-readable format along with detailed information (permissions, owner, etc.).
Display Sizes Including Hidden Files in a Specific Directory
ls -ah /var/log
Displays the sizes of all items, including hidden files, in a specified directory in human-readable units.
Installation
ls-h is not a command that is installed by default on the system. To conveniently use the functionality of 'ls -h', you can set up a custom alias or create a simple shell script.
Setting an Alias
alias ls-h='ls -h'
To use 'ls-h' as an alias for 'ls -h' during a shell session, enter the following command. For permanent use, you need to add it to your shell configuration file (e.g., ~/.bashrc, ~/.zshrc).
Permanent Alias Setup (Bash/Zsh)
echo "alias ls-h='ls -h'" >> ~/.bashrc
source ~/.bashrc
Add the alias command above to your ~/.bashrc or ~/.zshrc file and apply the changes.
Creating a Simple Shell Script
echo '#!/bin/bash\nls -h "$@"' > ~/bin/ls-h\nchmod +x ~/bin/ls-h
You can also create an executable script to make the 'ls-h' command. Create a script file, grant it execute permissions, and then save it in a directory included in your PATH (e.g., ~/bin).
Tips & Notes
Useful tips and points to note when using ls-h.
Combination with Other ls Options
If ls-h is an alias for 'ls -h', you can freely combine it with other useful options of the 'ls' command (e.g., -l, -a, -t, -r). For example, you can use it like 'ls-h -lat'.
- ls-h -l: Displays human-readable sizes with detailed information
- ls-h -a: Displays human-readable sizes including hidden files
- ls-h -t: Displays sorted by time with human-readable sizes
Alias vs. Script
For simple functions, an alias is convenient. However, if more complex logic or additional argument processing is required, a script approach is more flexible. In most cases, an alias for 'ls -h' is sufficient.