You're asking specifically about seeing file sizes in Kilobytes (K) or Megabytes (M)!
To display file sizes in these human-readable formats (K, M, G, etc.), you need to use the ls command with the -h option in conjunction with the long listing format (-l).
So, the command you're looking for is:
ls -lh
Let me demonstrate with an example of what you might see:
# First, let's create some files of different sizes
echo "This is a small file." > small_file.txt
head /dev/urandom | tr -dc A-Za-z0-9_ | head -c 100K > medium_file.txt
head /dev/urandom | tr -dc A-Za-z0-9_ | head -c 2.5M > large_file.txt
# Now, run ls -lh
ls -lh
Output might look something like this:
total 3.0M
-rw-rw-r-- 1 labex labex 2.5M Dec 17 03:07 large_file.txt
-rw-rw-r-- 1 labex labex 100K Dec 17 03:07 medium_file.txt
-rw-rw-r-- 1 labex labex 22 Dec 17 03:07 small_file.txt
In this output:
large_file.txtis displayed as2.5M(2.5 Megabytes)medium_file.txtis displayed as100K(100 Kilobytes)small_file.txtis22bytes (for very small files, it might still show the exact byte count, often without a unit or withBfor bytes).
So, remember: ls -lh is your go-to command for seeing file sizes in K or M!
Would you like to try creating some files and then using ls -lh to see this in your own environment?