File Commands Ls [Options] File Options -A: Show Hidden Files

Total Page:16

File Type:pdf, Size:1020Kb

File Commands Ls [Options] File Options -A: Show Hidden Files Linux Cheat sheet o: others -P: pattern is a perl regex df [options] file 3 Network & Remote by A.Mahouachi a: all -m: stop after m matches options: ssh [options] user@host ["cmd1;cmd2"] +: add mode -n: also show matching line number options: -h: human readable 1 File Commands -: remove mode -R: recurse directories -2: force protocol 2 =: exact mode -c: only show matching lines count -i: list inodes info ls [options] file -P: no dereference of sym links -o StrictHostKeyChecking=no: ignore options r: read –exclude=glob : exclude these warnings due to remote host key w: write –include=glob : only consider these 2 Process Commands change -a: show hidden files x: execute files and search for dirs -A: show hidden files except . and .. cat [options] file(s) ps [options] -X: forward X11 display X: search for dirs options -d: only show directories s: setuid or setguid options: wget [options] url -h: human readable size t: sticky bit -v: non ascii chars except tab and eol -e: all processes options: -i: inode info -T: show tabs numeric mode -f: full listing -b: run in background -l: long list format -t: equivalent to -vT -H: show hierarchy -o file: print wget output in file -m: output as csv format: [0-7]1,4 -E: show eol end of line example: 755 -p pid: this process pid -o /dev/null: suppress wget output -n: numeric uid and guid -e: equivalent to -vE -C cmd: this command name cmd -q: be quiet -r: sort in reverse order first digit: setuid(4), setguid(2) -A: equivalent to -vET second digit: owner perms -w: wide output -d: debug -S: sort by file size -s: remove repeat empty lines -ww: to show long command lines -O file: save response to file -t: sort by modification time third digit: group perms tail [options] file fourth digit: others perms -l: long listing, including wchan -c: resume file download tree [options] dir options -o x,y,z: show columns x y z -S: print server headers options read: 4 write: 2 -f: show end of file live -o user,pid,cmd: show columns user, -T N: timeout after N seconds -d: only directories execute: 1 -35: show last 35 lines pid command –user=user: basic http auth user -q: be quiet -N: negation –password=password: basic http auth -f: show full paths find path [options] [tests] [actions] -P pattern: only matching pattern head [options] file -u user: processes owned by user password options: –save-cookies file: save cookies to file -I pattern: except matching pattern options -u user -N: processes not owned by user -h: print sizes in human readable for- -mindepth: start from min level in hier- –sort=x,y: x y are columns in ps output –load-cookies file: use file as cookies mat archy -35: show first 35 lines –sort=user: sort by user –post-data=string -C: use colors -maxdepth: end with max level in hier- -q: be quiet –sort=+time: sort by cpu time asc –post-file=file -L max: max level depth archy tac file(s) –sort=-time: sort by cpu time desc –no-check-certificate: ignore ssl certifi- tests: print files starting from last line –sort=size: sort by memory size cate cp [options] source dest -name "xyz*": name like xyz* cut [options] file –sort=vsize: sort by vm size curl [options] url options: options -iname "xyz*": like -name but case in- options top [options] sensitive -b: backup dest before overwrite -d char: use char as delimiter -H header: like -H "Host: st.com" -type d: only directories options -u <user:password>: basic http auth -r: recursive -type f:only files -f 1,3,5: print fields 1, 3 and 5 -f: force -d x: refresh every x seconds -s: be silent -mtime 0: modified < 1 day uniq [options] input output -p pid1 -p pid2: only processes with -S: show errors if silent mode -l: link files instead of copy -mtime -x: modified < x days options -P: dont follow sym links pid1 pid2 -L: follow new location in case 301 -mtime +x: modified > x days -c: prefix lines by number of occur- -c : show command lines –data "field=value": x-www-form- -i: interactive -mmin: like -mtime but in minutes -u: copy only if source newer than dest rences interactive commands urlencoded query -size +100M: size > 100mb -d: only print duplicate lines space: udpdate display –data-binary data: post data as is wi- mv [options] source dest -size -100M: size < 100mb (k for kb, G -u: only print unique lines n: change number of displayed proces- thout encoding options for gb) sort [options] file ses –data-binary @filename: post filename -b: backup dest before overwrite -perm /o+w: writable by others options up and down: browse processes content as is -f: force ! -perm /o+r : not readable by others k: kill a process -X method: use PUT, GET, POST etc. actions: -n: numeric sort o: change order –request method: use PUT, GET, POST -i: interactive -b: ignore blank lines -u: move only if source newer than dest -print: print matching T: sort by time etc. -delete: rm matching files -f: ignore case ln [options] file link -r: reverse order A: sort by age mail [options] to-address options -exec cmd ’{}’ ; : run cmd for every P: sort by cpu options: match tar [options] file M: sort by memory -s: sym link (hard by default) -exec cmd ’{}’ + : run cmd at the end of options c: display/hide command line -s subject: email with subject -f: overwrite link if exists search -c address1,address2: cc copy -f file: archive file m: display/hide memory -b address1,address2: bcc copy -b: backup old link before overwrite -exec rm -rf ’’ : rm -rf matching items -c: create t: display/hide cpu -fprint /tmp/result: write matches to mail -s ’hello there’ ’[email protected]’ < so- rm [options] file -t: list f: manage list of displayed columns mefile options /tmp/result -x: extract up and down: move between columns -C DIR: cd to DIR 4 Terminal -f: force di [options] files d: display/hide the selected column Ctrl+C: halt current command -i: interactive options -z: gzip q: apply and quit the field mgmt -j: bzip2 Ctrl+Z: pause current command rm – -foo if file name is -foo screen bg %1: resume paused command in -r: recursive du [options] file chmod [options] mode file(s) -w: ignore whitespaces pgrep [options] pattern background options -B: ignore blank lines options: fg %1: resume paused command in fo- options -R: recursive -q: only show file names -c: a grand total reground -x".sync*": exclude files with path like -h: human readable -l : show pid and process name Ctrl+D: logout symbolic mode .sync* -L: dereference sym links -a : show pid and full command line Ctrl+W: remove a word from current format: [ugoa][[+-=][perms]],... -P: no dereference of sym links -n : if more than one show newest line example: u+x,o-wx,g-w grep [options] pattern files -s: total for each argument -o : if more than one show oldest Ctrl+U: remove current line u: owner options –exclude=pattern -u uid : show only processes of uid Ctrl+A: go to beginning of current line g: group -i: ignore case -max-depth=N: dont go deeper than N -c : count results Ctrl+E: go to end of current line.
Recommended publications
  • Linux Hardening Techniques Vasudev Baldwa Ubnetdef, Spring 2021 Agenda
    Linux Hardening Techniques Vasudev Baldwa UBNetDef, Spring 2021 Agenda 1. What is Systems Hardening? 2. Basic Principles 3. Updates & Encryption 4. Monitoring 5. Services 6. Firewalls 7. Logging What is System Hardening? ⬡ A collection of tools, techniques, and best practices to reduce vulnerability in technology applications, systems, infrastructure, firmware, and other areas ⬡ 3 major areas: OS vs Software vs Network ⬠ When have we done hardening in this class before? ⬠ This lecture is focusing mostly on OS and software level Why Harden? ⬡ Firewalls can only get us so far, what happens when at attack is inside the network? ⬠ If you have nothing protecting your systems you are in trouble ⬡ We want some kind of secondary protection A Few Cybersecurity Principles ⬡ Zero Trust Security ⬠ Instead of assuming everything behind the firewall is safe, Zero Trust verifies each request as though it originates from an unsecure network ⬡ Principle of Least Privilege ⬠ Only privileges needed to complete a task should be allowed ⬠ Users should not have domain administrator/root privileges ⬡ Principle of Least Common Mechanism ⬠ Mechanisms used to access resources should not be shared in order to avoid the transmission of data. ⬠ Shared resources should not be used to access resources The Threat Model ⬡ A process by which potential threats can be identified and prioritized. ⬠ If you have a web server that feeds input to a mysql database, then protecting against mysql injections would be prioritized in your model. 2 considerations ⬡ *nix like is a very
    [Show full text]
  • HP-UX Fundamentals
    Contact Us: (616) 875-4060 HP-UX Essentials Course Summary Length: 3 Days Prerequisite: Basic computer skills Recommendation Statement: Student should be able to use a computer monitor, keyboard, mouse. Student needs to be able to input commands and control characters from a keyboard. Course Description: For those new to HP-UX, this is the first course you will take. The course starts at the beginner level and works into intermediate and advanced HP-UX commands and utilities. The student is introduced to the HP-UX Korn shell, the command line and command syntax. Although you will be exposed to the various windowing platforms available in HP-UX, this course teaches UNIX at “the command line level” to develop a thorough understanding of the HP-UX operating environment. The student learns how to navigate the HP-UX file systems and how to work with files, directories and permissions. The student will learn how to use the HP-UX editors “ex” and “vi. “ Once the student is comfortable with basic HP-UX commands, they’ll move onto advanced power tools as well as how to customize the POSIX Korn shell. The classroom labs are run in a real-world UNIX environment, are structured to allow you to learn by doing, and are developed to simulate “real world” situations. The hands-on labs progressively build your HP-UX knowledge and command skills in a clear and concise manner. Working in a controlled UNIX classroom environment with an expert instructor, you will learn HP-UX concepts and commands. You will receive professional tips and techniques that will help you build your HP-UX confidence and skills.
    [Show full text]
  • Full Workload
    Command Line: Process Control C@ELOLJ<I GifZ\jjXe[afYZfekifc =LCCNFIBCF8; !Qn\`Ycld#g_fkfZXj\%Zfd What is happening on your Linux machine? Various shell commands All of these parameters can be com- bined – for example, pstree -apu. give you details about system processes and help you control them. C`jk`e^GifZ\jj\jn`k_gj BY HEIKE JURZIK The ps command gives you a list of the processes currently running on your sys- henever you or an application ing. All other processes share this com- tem. If you do not specify any command- launch a program, the operat- mon “ancestor” – init starts the operat- line parameters, the tool will restrict the Ning system starts one or multi- ing system’s basic programs. pstree list to the current shell. If you are inter- ple processes. These processes can enter shows the relationship between “parent” ested in all of your processes, call ps various states: They can be processed, and “child” processes. This tree struc- with the x option (Listing 1). stopped, restarted, and – under normal ture shows you at a glance who is de- The tabular output in the shell tells circumstances – stopped again. Linux scended from whom (Figure 1). you the following characteristics: has something similar to access controls ฀ PID: The process identifier, a unique for processes: Only the user that started 8[[`k`feXcFlkglk number that you can use to reference a process can stop, restart, or terminate The tool gives you more detailed output a process individually. the process. if you set the -a flag. This tells pstree to ฀ TTY: The terminal or console on The only exception to this rule is the show you, in addition, the parameters which the process was started.
    [Show full text]
  • LFS-BOOK.Pdf
    Linux From Scratch Версия 7.3 Автор Gerard Beekmans Редакторы Matthew Burgess и Bruce Dubbs Перевод Иван Лабутин Linux From Scratch: Версия 7.3 by Автор Gerard Beekmans, Редакторы Matthew Burgess и Bruce Dubbs, Перевод Иван Лабутин Copyright © 1999-2013 Gerard Beekmans Copyright © 1999-2013, Gerard Beekmans Все права защищены. Эта книга выпущена под лицензией Creative Commons License. Команды для компьютера могут быть извлечены из книги под лицензией MIT License. Linux® зарегистрированная торговая марка Linus Torvalds. Linux From Scratch - Версия 7.3 Содержание Пролог ......................................................................................................................... viii i. Предисловие ........................................................................................................ viii ii. Кому адресована эта книга? ............................................................................... ix iii. Целевые архитектуры LFS .................................................................................. x iv. LFS и стандарты .................................................................................................. x v. Пояснения к выбранным пакетам ..................................................................... xii vi. Необходимые знания ....................................................................................... xvii vii. Требования к хост-системе ........................................................................... xviii viii. Соглашения, используемые в книге .............................................................
    [Show full text]
  • Linux Shell Scripting Cookbook Second Edition
    Linux Shell Scripting Cookbook Second Edition Over 110 practical recipes to solve real-world shell problems, guaranteed to make you wonder how you ever lived without them Shantanu Tushar Sarath Lakshman BIRMINGHAM - MUMBAI Linux Shell Scripting Cookbook Second Edition Copyright © 2013 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: January 2011 Second edition: May 2013 Production Reference: 1140513 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78216-274-2 www.packtpub.com Cover Image by Parag Kadam ([email protected]) Credits Authors Project Coordinator Shantanu Tushar Shiksha Chaturvedi Sarath Lakshman Proofreader Reviewers Linda Morris Rajeshwari K. John C. Kennedy Indexer Hemangini Bari Anil Kumar Sudhendu Kumar Production Coordinator Aravind SV Shantanu Zagade Acquisition Editor Cover Work Kartikey Pandey Shantanu Zagade Lead Technical Editor Ankita Shashi Technical Editors Jalasha D'costa Amit Ramadas Lubna Shaikh About the Authors Shantanu Tushar is an advanced GNU/Linux user since his college days.
    [Show full text]
  • Bash Guide for Beginners
    Bash Guide for Beginners Machtelt Garrels Xalasys.com <tille wants no spam _at_ xalasys dot com> Version 1.8 Last updated 20060315 Edition Bash Guide for Beginners Table of Contents Introduction.........................................................................................................................................................1 1. Why this guide?...................................................................................................................................1 2. Who should read this book?.................................................................................................................1 3. New versions, translations and availability.........................................................................................2 4. Revision History..................................................................................................................................2 5. Contributions.......................................................................................................................................3 6. Feedback..............................................................................................................................................3 7. Copyright information.........................................................................................................................3 8. What do you need?...............................................................................................................................4 9. Conventions used in this
    [Show full text]
  • 50 Most Frequently Used UNIX / Linux Commands (With Examples)
    17/10/13 50 Most Frequently Used UNIX / Linux Commands (With Examples) Home Free eBook Start Here Archives Contact About 50 Most Frequently Used UNIX / Linux Commands (With Examples) by Ramesh Natarajan on November 8, 2010 290 Curtir 375 Tw eet 325 This article provides practical examples for 50 most frequently used commands in Linux / UNIX. This is not a comprehensive list by any means, but this should give you a jumpstart on some of the common Linux commands. Bookmark this article for your future reference. Did I miss any frequently used Linux commands? Leave a comment and let me know. 1. tar command examples Create a new tar archive. $ tar cvf archive_name.tar dirname/ Extract from an existing tar archive. $ tar xvf archive_name.tar View an existing tar archive. www.thegeekstuff.com/2010/11/50-linux-commands/ 1/32 17/10/13 50 Most Frequently Used UNIX / Linux Commands (With Examples) $ tar tvf archive_name.tar More tar examples: The Ultimate Tar Command Tutorial with 10 Practical Examples 2. grep command examples Search for a given string in a file (case in-sensitive search). $ grep -i "the" demo_file Print the matched line, along with the 3 lines after it. $ grep -A 3 -i "example" demo_text Search for a given string in all files recursively $ grep -r "ramesh" * More grep examples: Get a Grip on the Grep! – 15 Practical Grep Command Examples 3. find command examples Find files using file-name ( case in-sensitve find) # find -iname "MyCProgram.c" Execute commands on files found by the find command $ find -iname "MyCProgram.c" -exec md5sum {} \; Find all empty files in home directory # find ~ -empty More find examples: Mommy, I found it! — 15 Practical Linux Find Command Examples 4.
    [Show full text]
  • Linux Shell Scripting Tutorial V2.0
    Linux Shell Scripting Tutorial v2.0 Written by Vivek Gite <[email protected]> and Edited By Various Contributors PDF generated using the open source mwlib toolkit. See http://code.pediapress.com/ for more information. PDF generated at: Mon, 31 May 2010 07:27:26 CET Contents Articles Linux Shell Scripting Tutorial - A Beginner's handbook:About 1 Chapter 1: Quick Introduction to Linux 4 What Is Linux 4 Who created Linux 5 Where can I download Linux 6 How do I Install Linux 6 Linux usage in everyday life 7 What is Linux Kernel 7 What is Linux Shell 8 Unix philosophy 11 But how do you use the shell 12 What is a Shell Script or shell scripting 13 Why shell scripting 14 Chapter 1 Challenges 16 Chapter 2: Getting Started With Shell Programming 17 The bash shell 17 Shell commands 19 The role of shells in the Linux environment 21 Other standard shells 23 Hello, World! Tutorial 25 Shebang 27 Shell Comments 29 Setting up permissions on a script 30 Execute a script 31 Debug a script 32 Chapter 2 Challenges 33 Chapter 3:The Shell Variables and Environment 34 Variables in shell 34 Assign values to shell variables 38 Default shell variables value 40 Rules for Naming variable name 41 Display the value of shell variables 42 Quoting 46 The export statement 49 Unset shell and environment variables 50 Getting User Input Via Keyboard 50 Perform arithmetic operations 54 Create an integer variable 56 Create the constants variable 57 Bash variable existence check 58 Customize the bash shell environments 59 Recalling command history 63 Path name expansion 65 Create and use aliases 67 The tilde expansion 69 Startup scripts 70 Using aliases 72 Changing bash prompt 73 Setting shell options 77 Setting system wide shell options 82 Chapter 3 Challenges 83 Chapter 4: Conditionals Execution (Decision Making) 84 Bash structured language constructs 84 Test command 86 If structures to execute code based on a condition 87 If.
    [Show full text]
  • Killing Processes This Tip Shows You Some Interesting Ways to Kill Stubborn Processes
    http://www.linuxhowtos.org/Tips and Tricks/kill_processes.pdf Killing Processes This tip shows you some interesting ways to kill stubborn processes. Never let it be said that you can't kill a process again! The first way is the old boring way that most people probably use. Use the command ps aux, look through the process list until you find the PID you want and issue the kill command. How tedious! Alternatively, try using the killall command which will automatically kill a program based on its name. Code Listing 1 # killall mozilla-bin But what if you only know part of the name? Well, you could combine ps with grep, kill and awk to produce something like this. Code Listing 2 # ps aux | grep mozilla | awk '{print $2}' | xargs kill But, there's a far simpler way. Enter pkill and the closely related pgrep. These commands are part of the sys-apps/procps package and are designed to search for (or kill) running processes. So the previous command could be replaced with the following: Code Listing 3 # pkill mozilla Note: To list the PIDs instead of killing them, use pgrep. Finally, what if you have a runaway process hogging /dev/dsp, or some other file/socket? You can use fuser, which displays the PIDs of process using a specified file or filesystem. Or give it the -k option, like this, and you can easily kill those processes: Code Listing 4 # fuser -k /dev/dsp From http://www.gentoo.org/news/en/gwn/20030707-newsletter.xml image:rdf newsfeed / //static.linuxhowtos.org/data/rdf.png (null) | image:rss newsfeed / //static.linuxhowtos.org/data/rss.png
    [Show full text]
  • Wildcards and Regular Expressions.Shw
    Wildcards and Regular Expressions Hour 9 PObjectives <Regular expressions <File name wild cards and hiding wild cards from the shell <Searching for strings and patterns: grep, fgrep, and egrep Copyright © 1998-2002 Delroy A. Brinkerhoff. All Rights Reserved. Hour 9 Unix Slide 1 of 12 Regular Expressions A formal language PFormal (computer) languages are categorized by their strength (i.e., by the complexity of the grammar they accept) PRegular expressions are the simplest of these languages PRegular expressions are formed with metacharacters <Some characters just represent themselves <Metacharacters have an extended, regular expression meaning <The set of metacharacters and the associated meaning vary between regular expression languages (i.e., the regular expression language accepted by Unix commands is not always the same) Hour 9 Unix Slide 2 of 12 Wildcards File name shortcuts PWildcard characters <Simplified (subset of) regular expression <Shortcut method of specifying –a single file name – multiple file names with one expression < Implemented or expanded by the shell (Bourne, Korn, C, & others) – Wildcards work with any command (including user-written programs) that accepts multiple file names on the command line PIf these characters are interpreted by a command, they can be hidden from the shell with quotation marks < " (double quote marks) inhibit wildcard expansion < ' (single quote marks) inhibit wildcard expansion, variable substitution ($varname), and command substitution (introduced later) Hour 9 Unix Slide 3 of 12 Wildcard
    [Show full text]
  • Intermediate Linux
    Intermediate Linux th st !!***May subroutine 30 mpi_utils_step_parallel_edge– 31 , 2016 implicit none integer ele, ierr do ele = 1, nfaces Lecturerscall mpi_isend(commvec(ele)%field1(commvec(ele)%out_i1, (in alphabetical order): & & commvec(ele)%out_j1, & Jaakko& Leinonen commvec(ele)%out_k1), & Tomasz& 1, commvec(ele)%mpi_type_out1,Malkiewicz & & commvec(ele)%to_id, commvec(ele)%to_id, & Thomas& MPI_COMM_WORLD, Zwinger send_reqs(ele), ierr) if(ierr /= MPI_SUCCESS) then call pio_abort(ierr) end if call mpi_isend(commvec(ele)%field2(commvec(ele)%out_i2, & & commvec(ele)%out_j2, & & commvec(ele)%out_k2), & & 1, commvec(ele)%mpi_type_out2, & & commvec(ele)%to_id, commvec(ele)%to_id+tag_offset, & & MPI_COMM_WORLD, send_reqs(nfaces+ele), ierr) if(ierr /= MPI_SUCCESS) then call pio_abort(ierr) end if end do #ifdef NONBLOCK do ele = 1, nfaces All material (C) 2016 by the authors. call mpi_irecv(commvec(ele)%field1(commvec(ele)%in_i1, & This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported & commvec(ele)%in_j1, & 1 License, http://creativecommons.org/licenses/by-nc-sa/3.0/ 2 & commvec(ele)%in_k1), & & 1, commvec(ele)%mpi_type_in1, & Program, May 30th 09:30 – 10:00 Morning coffee & registration 10:00 – 10:15 Introduction to the course (whereabouts, etc.) 10:15 – 10:45 Recapping Introduction to Linux (to refresh memory) 10:45 – 11:30 Basic concepts of shells 11:30 – 12:30 Lunch 12:30 – 14:30 Working with the Bash shell 14:30 – 15:00 Coffee 15:00 – 15:45 Bash job management and signals About This Course 15:45 – 16:30 Hands-on exercises & Troubleshooter: Interactive session to deal with open questions and specific problems 3 4 Program, May 31st How We Teach 09:00 – 10:00 Pipes, named pipes and redirecting All topics are presented with interactive demonstrations.
    [Show full text]
  • Introduction to Linux
    Introduction to Linux A Hands on Guide Machtelt Garrels CoreSequence.com <[email protected]> Version 1.8 Last updated 20030916 Edition Introduction to Linux Table of Contents Introduction.........................................................................................................................................................1 1. Why this guide?...................................................................................................................................1 2. Who should read this book?.................................................................................................................1 3. New versions of this guide...................................................................................................................1 4. Revision History..................................................................................................................................1 5. Contributions.......................................................................................................................................2 6. Feedback..............................................................................................................................................2 7. Copyright information.........................................................................................................................3 8. What do you need?...............................................................................................................................3 9. Conventions used
    [Show full text]