Comando cat en Linux con ejemplos

El comando cat (concatenar) se usa con mucha frecuencia en Linux. Lee datos del archivo y da su contenido como salida. Nos ayuda a crear, visualizar, concatenar archivos. Así que veamos algunos comandos cat usados ​​con frecuencia. 

 1) Para ver un comando de un solo archivo :
 
 

$cat filename

Producción 
 

It will show content of given filename

2) Para ver varios archivos  
Comando: 
 

$cat file1 file2

Producción 
 

This will show the content of file1 and file2.

3) Para ver el contenido de un archivo que precede con números de línea.  
Dominio: 
 

$cat -n filename

Producción 
 

It will show content with line number
example:-cat-n  geeks.txt
1)This is geeks
2)A unique array

4) Crear un comando de archivo  :
 
 

$cat > newfile

Producción 
 

Will create a file named newfile

5) Copie el contenido de un archivo a otro archivo.  
Dominio: 
 

$cat [filename-whose-contents-is-to-be-copied] > [destination-filename]

Producción 
 

The content will be copied in destination file

6) El comando Cat puede suprimir líneas vacías repetidas en el  
comando de salida: 
 

$cat -s geeks.txt

Producción 
 

Will suppress repeated empty lines in output

7) El comando Cat puede agregar el contenido de un archivo al final de otro archivo.  
Dominio: 
 

$cat file1 >> file2

Producción 
 

Will append the contents of one file to the end of another file

8) El comando Cat puede mostrar el contenido en orden inverso usando el comando tac.  
Dominio: 
 

 $tac filename

Producción 
 

Will display content in reverse order 

9) El comando Cat puede resaltar el final de la línea.  
Dominio: 
 

$cat -E "filename"

Producción 
 

Will highlight the end of line

10) Si desea usar la opción -v, -E y -T juntas, en lugar de escribir -vET en el comando, puede usar la opción de línea de comando -A.  
Dominio 
 

$cat -A  "filename"

11) Comando Cat para abrir archivos discontinuos.  
Dominio: 
 

$cat -- "-dashfile"

Producción 
 

Will display the content of -dashfile

12) Comando Cat si el archivo tiene mucho contenido y no cabe en la terminal.  
Dominio: 
 

$cat "filename" | more

Producción 
 

Will show that much content, which could fit in terminal and will ask to show more.

13) Comando Cat para fusionar el contenido de varios archivos.  
Dominio: 
 

$cat "filename1" "filename2" "filename3" > "merged_filename"

Producción 
 

Will merge the contents of file in respective order and will insert that content in "merged_filename".

14) Comando Cat para mostrar el contenido de todos los archivos de texto en la carpeta.  
Dominio: 
 

$cat *.txt

Producción 
 

Will show the content of all text files present in the folder.

15) Comando Cat para escribir en un archivo ya existente. 

Dominio :

$cat >> geeks.txt
The newly added text.

Producción

Will append the text "The newly added text." to the end of the file.

?list=PLqM7alHXFySFc4KtwEZTANgmyJm3NqS_L 

 

Este artículo es una contribución de Pranav . Si te gusta GeeksforGeeks y te gustaría contribuir, también puedes escribir un artículo usando write.geeksforgeeks.org o enviar tu artículo por correo a review-team@geeksforgeeks.org. Vea su artículo que aparece en la página principal de GeeksforGeeks y ayude a otros Geeks. 

 

Escriba comentarios si encuentra algo incorrecto o si desea compartir más información sobre el tema tratado anteriormente.

 

Publicación traducida automáticamente

Artículo escrito por GeeksforGeeks-1 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *