-2

Using a pipe, sort a directory listing (i.e. list contents of directory and sort)… then pipe this output into cat and redirect the output into a file named “exercise5.7.txt”. I sorted the list contents of the directory. Just need help with how to pipe the output into cat and redirect the output. If someone could give me an example, I'd deeply appreciate it.

k-ramamunroe1@acadnx:~$ ls|sort
biglist
ciss100
list1
list2
ls
names.txt
ramamunroekamanzilink.txt
ramamunroekamanziLL.ba
slist
sort
users
k-ramamunroe1@acadnx:~$

3 Answers3

0

Just put a > sign after it:

$/tmp$ echo "asdsd" > file1
$/tmp$ cat file1 > file2
$/tmp$ cat file2
asdsd
kagronick
  • 2,552
  • 1
  • 24
  • 29
0

Following example help you to get idea how sort and cat commands works according to your requirement.

kasun@kasunr:~/test/sort$ ls
1  45  67  78
kasun@kasunr:~/test/sort$ ls -a
.  ..  1  45  67  78

kasun@kasunr:~/test/sort$ ls -al | sort
drwxrwxr-x 2 kasun kasun 4096 ජූලි    3 09:45 .
drwxrwxr-x 3 kasun kasun 4096 ජූලි    3 09:45 ..
-rw-rw-r-- 1 kasun kasun    0 ජූලි    3 09:45 1
-rw-rw-r-- 1 kasun kasun    0 ජූලි    3 09:45 45
-rw-rw-r-- 1 kasun kasun    0 ජූලි    3 09:45 67
-rw-rw-r-- 1 kasun kasun    0 ජූලි    3 09:45 78
total 8
kasun@kasunr:~/test/sort$ ls -al | sort > sort.txt
kasun@kasunr:~/test/sort$ cat sort.txt 
drwxrwxr-x 2 kasun kasun 4096 ජූලි    3 09:46 .
drwxrwxr-x 3 kasun kasun 4096 ජූලි    3 09:45 ..
-rw-rw-r-- 1 kasun kasun    0 ජූලි    3 09:45 1
-rw-rw-r-- 1 kasun kasun    0 ජූලි    3 09:45 45
-rw-rw-r-- 1 kasun kasun    0 ජූලි    3 09:45 67
-rw-rw-r-- 1 kasun kasun    0 ජූලි    3 09:45 78
-rw-rw-r-- 1 kasun kasun    0 ජූලි    3 09:46 sort.txt
total 8
kasun@kasunr:~/test/sort$ 
Kasun Rathnayaka
  • 483
  • 4
  • 15
0

You just need to do as follows, but it will list all files also.

  ls|sort > exercise5.7.txt

If you prefer to list only directories

ls -d */ |sort > exercise5.7.txt
Steephen
  • 14,645
  • 7
  • 40
  • 47