11/07/2026

S/4HANA System Refresh: A Step-by-Step Guide for Basis Teams

Refreshing an S/4HANA QA or dev system from Production is routine work, but the post-refresh list runs longer than it did on classic ECC — embedded analytics, Fiori, and logical-system-sensitive configuration all need their own pass.

Before you start: the pre-refresh checklist

  • Freeze transports into the target system for the duration of the refresh.
  • Record every RFC destination and logical system name currently configured on the target ‚Äî you'll need to restore some of these after the DB copy overwrites them.
  • Export any client-specific configuration you don't want silently replaced by Production's values.
  • Confirm the backup/restore or snapshot window with the DBA/HANA team and the business calendar ‚Äî not just the technical window.

Two ways to move the data

HANA backup and restore: take a data backup from source, restore it to target. Straightforward, works across any infrastructure, but slower on large databases. Storage or array snapshot: a DBA/storage-team-driven copy at the disk layer, far faster for large systems, but it needs infrastructure support for snapshotting and cloning to already exist. Pick based on your downtime budget, not habit.

Core Basis steps

  1. Stop SAP on the target and take a backup of the target first, in case anything requires a rollback.
  2. Restore or snapshot the HANA database from source onto the target.
  3. Run post-processing: BDLS to rename the logical system, SCC4 to correct client settings, SM59 to repoint RFC destinations away from production endpoints, and clear the number range buffer.
  4. Reschedule or re-trigger background jobs lost in the refresh — see our background job troubleshooting guide if any come back cancelled instead of simply missing.
  5. Reapply the license key with SLICENSE — a full database-level copy wipes the one the target had.
  6. Reset <sid>adm and database user passwords to target-specific values. Never leave production credentials live in a lower system after a refresh.

S/4HANA-specific extras

  • Refresh the Fiori Launchpad and ICF service cache ‚Äî stale service registrations are a common cause of tiles failing to load right after a refresh.
  • Re-check client-dependent authorizations on embedded analytics CDS views; these don't always carry over cleanly from a BDLS rename.
  • Update the refreshed system's registration in Solution Manager / your landscape tool so monitoring and EWA reports point at the right SID again.

The most expensive mistake to get wrong

Outbound interfaces firing against production endpoints because RFC destinations weren't repointed before the system came back up. This is the single costliest post-refresh mistake — a test message, an EDI document, or a payment run can leave the lower system and land in a live production process. Repoint and lock down outbound RFCs and interfaces before starting SAP on the target, not after.

FAQ

What is BDLS used for after an SAP system refresh?

BDLS renames the logical system in a client after a refresh or copy, so documents and interfaces reference the correct (target) system instead of still pointing at the source system's identity.

Why does my SAP system try to send data to production after a refresh?

Because RFC destinations and interfaces copied over from production still point at live production endpoints. Repoint SM59 destinations and disable or redirect outbound interfaces before starting the system on the target.

Do I need a new license key after an SAP system copy?

Yes — a full database-level copy or restore invalidates the target's existing license, since the license is tied to the system's hardware key. Reapply it through SLICENSE after the copy.

SAP HANA Backup and Recovery: A Practical Guide for Basis Admins

HANA runs in-memory, but durability still depends entirely on backup discipline — the persistence layer and the log area need to be backed up on purpose, on a schedule, the same as any other database.

The two backups HANA always needs

A data backup is a full copy of the persistence layer at a point in time. Log backups run continuously in the background and are what makes point-in-time recovery possible between data backups. Skip log backups and you can only ever restore to the last data backup, losing everything after it.

File-based vs Backint

File-based backups write straight to a filesystem path — simplest to set up, fine for small or dev systems. Backint is the integration interface most production landscapes actually use, letting a third-party backup tool (Commvault, NetBackup, and similar) manage HANA backups the same way it manages everything else in the landscape, with retention and offsite copy handled centrally.

Triggering a manual data backup

Through HANA Cockpit's Backup tile, or directly in SQL:

BACKUP DATA USING FILE ('backup_name')

Checking backup health

Don't assume backups succeeded just because nothing paged you. Query the catalog directly:

SELECT * FROM M_BACKUP_CATALOG ORDER BY SYS_START_TIME DESC;
SELECT * FROM M_BACKUP_CATALOG_FILES WHERE BACKUP_ID = '<id>';

Look specifically for gaps in log backups, not just failed data backups — a silent gap there is what turns a routine restore into a bigger data-loss event than anyone expected.

Point-in-time recovery, at a glance

Recovery replays the most recent data backup and then every log backup up to the timestamp you choose. In practice: stop the system (or the affected tenant in a multi-tenant setup), open the recovery wizard in HANA Cockpit or Studio, choose "recover to point in time," and select the timestamp. HANA handles replaying the chain of backups itself — you don't manually restore files.

Common pitfalls

  • Log area filling up. Usually caused by log backups being disabled or the backup destination becoming unreachable ‚Äî this is a classic cause of a HANA system hanging with no obvious error.
  • Stale backup catalog pointers. After a storage migration, the catalog can still point at the old backup destination path. Verify it explicitly rather than assuming the migration updated everything.
  • Forgetting SYSTEMDB in multi-tenant (MDC) systems. SYSTEMDB holds the catalog and tenant metadata ‚Äî back it up alongside the tenant databases, not instead of them.

FAQ

How often should SAP HANA log backups run?

Continuously, in the background, by default — they're what makes point-in-time recovery possible. The setting to check is the backup destination and retention, not a schedule, since HANA writes log backups as segments fill rather than on a fixed timer.

What happens if the HANA log area fills up?

The database can hang or stop accepting writes, because it can't log new transactions. This is most often caused by log backups failing silently — an unreachable backup destination or Backint agent issue — rather than by transaction volume alone.

Can I restore an SAP HANA database to a specific point in time?

Yes — HANA's recovery process replays the most recent data backup plus the chain of log backups up to the timestamp you choose, through HANA Cockpit, Studio, or the command-line recovery tools.

STMS Transport Troubleshooting: Fixing Failed and Stuck SAP Transports

A stuck transport blocks everything scheduled behind it in the same queue, so it's worth treating as the first thing you fix in a morning, not the last. Start with the return code — it tells you which of a small number of actual problems you have.

Read the return code before you touch anything

  • RC0 ‚Äî success, nothing to do.
  • RC4 ‚Äî warnings only; usually fine, but worth a glance at the log if the transport affects something critical.
  • RC8 ‚Äî errors, most often objects that imported but didn't activate. Go to SE80 and check the objects in the transport.
  • RC12 ‚Äî a severe error during import; read the full log, don't just retry blind.
  • RC18 ‚Äî the transport was aborted or not found; check that the data and cofile actually made it to the target's transport directory.

Stuck "in process" and the queue won't move

First check whether the background job that actually runs imports (RDDIMPDP) is still active on the target — if it died, nothing moves no matter how many times you re-trigger from STMS. Then check the transport buffer:

tp showbuffer <SID>

If the buffer looks out of sync with what STMS shows, reset it the safe way rather than touching files under /usr/sap/trans by hand:

tp cleanbuffer <SID>

Authorization failures during import

These get missed because people check the developer's dialog-user authorizations and stop there. The import itself runs under the RFC background user or <sid>adm, which needs S_TRANSPRT and S_CTS_ADMI — check that user's roles, not the developer's.

Objects import but won't activate

Almost always a sequencing problem: a data element imported before its domain, or a structure before a table it depends on. Run a mass activation in SE80 first — it often resolves the dependency order on its own. If it doesn't, re-export the missing prerequisite object into a follow-up transport.

Two OS-level commands worth knowing by heart

# Connection test between systems
R3trans -d

# Check the import queue for a target SID from the command line
tp connect R3<DBSID> <SID>

Don't confuse transport routes with SAP Router

STMS transport routes control which systems a change object can move between; SAP Router is a completely separate network-level relay that lets SAP support and remote systems reach your landscape through a firewall. The two get mixed up constantly because both involve the word "routing." If you're troubleshooting connectivity rather than a change failing to import, you're looking for the latter — see SAP Router Installation step by step.

FAQ

What does RC8 mean in a SAP transport log?

RC8 means the import completed with errors — most commonly that one or more objects imported into the target system but failed to activate. Check SE80 for the specific objects named in the transport log.

Why is my transport stuck in the import queue?

Usually one of two things: the RDDIMPDP background job that actually processes imports has stopped running on the target, or the transport buffer is out of sync with what STMS is showing. Check the job first, then the buffer with tp showbuffer.

How do I check the SAP transport buffer from the command line?

Run tp showbuffer <SID> as the system's administrator user. To reset a buffer that's out of sync, use tp cleanbuffer <SID> rather than editing files under /usr/sap/trans directly.

SAP Background Job Troubleshooting: Why Jobs Get Cancelled and How to Fix Them

Background jobs are invisible right up until one fails during month-end close and three people are suddenly watching you troubleshoot it live. SM37 is where you start, but it rarely tells the whole story on its own.

Start in SM37, not the ticket

Pull up the job by name and date range and check its status first: Scheduled and Released mean it hasn't run yet; Ready means it's waiting for a free background work process; Active means it's running now; Cancelled is what you're here for. Open the job log before anything else — it almost always names the failing step.

The five most common cancellation causes

  1. ABAP runtime error. The job log references a short dump — go straight to ST22 and read it; the dump text usually names the exact statement that failed.
  2. No free background work process. The job sat in Ready for a long stretch before cancelling. Check SM50/SM66 for work process saturation and RZ04 for how many background processes the current operation mode allocates.
  3. The job's user got locked or its password changed mid-run. A dialog user's password expiring under a scheduled job is one of the most common silent killers. Use a dedicated background/service user with a non-expiring password for anything scheduled.
  4. A missing or changed variant. Someone deleted or renamed the variant the job step points to. Check the Step tab in SM37 against what actually exists in SA38.
  5. Authorization failure. The job runs under a user that's missing a role needed by that specific step. SU53 right after the failure, or an ST01 authorization trace if SU53 doesn't catch it, will show the missing object.

Reading the return code correctly

Don't conflate three different things that all get called "the RC": the job's overall status in SM37, the ABAP step's own return code, and — for jobs that call external programs like tp — that program's separate return code scale. Check the job log's return code first; it tells you which of the three you're actually looking at.

Cross-check the system log

SM21, filtered to the job's time window, catches what ABAP never reports to the job log at all — a full archive filesystem, a database connection drop, an OS-level resource limit. If ST22 shows nothing but the job still cancelled, this is the next place to look.

Preventing the next one

  • Spread jobs across job classes A/B/C instead of scheduling everything for the top of the hour.
  • Use a dedicated, non-expiring background user for scheduled jobs ‚Äî never a named dialog user's ID.
  • Monitor proactively with RZ20/CCMS or an external monitoring tool, rather than waiting for the business to report a missed job.
  • For jobs that depend on each other, use event-based scheduling instead of fixed time gaps ‚Äî a slow upstream job otherwise cancels the downstream one for "missing data" that was simply still being written.

FAQ

What does job status "Cancelled" mean in SM37?

It means the job started but didn't complete — it stopped partway through a step rather than finishing normally. The job log for that run names the step and, usually, the reason.

How do I find out why a background job failed?

Open the job log in SM37 first. If it points to a short dump, check ST22. If it shows nothing specific, check SM21 for the same time window for an OS or database-level cause ABAP wouldn't have reported.

Can a locked user cause a background job to fail?

Yes — if the user the job runs under gets locked, has its password expire, or loses a required role mid-schedule, the job cancels with an authorization or logon error even though nothing about the job itself changed.

Top 20 Linux Commands Every SAP Basis Administrator Should Know

Most SAP systems built today run on Linux — SUSE or Red Hat under S/4HANA — which means Basis work increasingly starts at the OS prompt, not inside SAPGUI. These twenty commands cover the five things you'll reach for daily: watching the system, controlling the SAP instance, reading logs, moving files, and checking connectivity.

System and process monitoring

  • ps -ef | grep <sid>adm ‚Äî confirm which SAP work processes are actually running under the instance owner.
  • top ‚Äî live CPU and memory by process; the first stop when a system "feels slow."
  • free -h ‚Äî memory and swap in human-readable units; check swap usage before blaming the application.
  • df -h ‚Äî filesystem usage by mount point; the classic cause of a stuck archive or spool is a full filesystem.
  • du -sh * ‚Äî size up a directory's contents when df says a filesystem is full but you don't know what's eating it.

Controlling the SAP instance from the OS

  • su - <sid>adm ‚Äî switch to the SAP administrator user with its full environment loaded.
  • sapcontrol -nr <NN> -function GetProcessList ‚Äî the OS-level equivalent of SM51, useful when SAPGUI itself won't connect.
  • startsap / stopsap ‚Äî start or stop the instance cleanly instead of killing processes by hand.

Reading logs without opening SAPGUI

  • tail -f dev_w0 ‚Äî follow a work process trace live while reproducing an issue.
  • grep -i error dev_w* ‚Äî scan every work process trace for errors in one pass.
  • less ‚Äî page through a large trace or log file without loading the whole thing into an editor.
  • zgrep / zcat ‚Äî search or view rotated, gzip-compressed logs without decompressing them first.

Finding and moving files

Full walkthroughs of these two live on this blog already — command reference here, details in the linked posts.

  • find /usr/sap/<SID> -name "*.trc" -mtime +30 ‚Äî locate trace files older than 30 days before a cleanup. See The Linux find Command.
  • tar --list --verbose --file archive.tar.gz ‚Äî inspect an archive's contents before extracting it. See The TAR command | Bash Basics.
  • scp file.tar.gz user@host:/path/ ‚Äî copy a file securely between SAP hosts.

Networking and connectivity checks

  • ping <host> ‚Äî confirm basic reachability before chasing an RFC error.
  • telnet <host> <port> (or nc -zv <host> <port>) ‚Äî check whether a specific port is actually open; this catches firewall issues telnet-to-host alone misses.
  • ss -tulpn ‚Äî list listening ports and the process holding each one; the modern replacement for netstat.

Editors, permissions, and the rest

  • vi / vim ‚Äî unavoidable for editing config on a server with no GUI. See VI Shortcuts & Commands For Newbies and How to Exit From VIM (VI)? if :wq isn't yet muscle memory.
  • sudo <command> ‚Äî run a single command with elevated rights without logging in as root. See Linux Commands For Beginners: SUDO.
  • chmod / chown ‚Äî fix file permission and ownership issues, a common cause of a work process failing to write its own trace file.
  • crontab -l ‚Äî check what's scheduled on the OS level, separate from SAP's own job scheduler.

Quick reference

CommandUse it for
ps -ef | grep sidadmConfirm SAP work processes are running
top / free -hCPU, memory, swap at a glance
df -h / du -shFilesystem space and what's using it
sapcontrol -function GetProcessListSM51 from the OS prompt
tail -f / grep / less / zgrepReading and searching logs
find / tar / scpLocating, archiving, and moving files
ping / nc -zv / ss -tulpnConnectivity and port checks
vi / sudo / chmod / chownEditing config and fixing permissions

FAQ

Do SAP Basis administrators need to know Linux?

Yes — most current SAP installations, especially S/4HANA, run on SUSE or Red Hat Enterprise Linux. SAPGUI covers application-level administration, but instance control, log review, and OS-level troubleshooting all happen at the Linux command line.

What command switches to the SAP administrator user?

su - <sid>adm switches to the SAP system's administrator account with its environment (paths, SAP-specific variables) loaded, which plain su <sid>adm without the dash does not do.

How do I check if SAP work processes are running from the OS?

Run ps -ef | grep <sid>adm to see the raw OS processes, or sapcontrol -nr <NN> -function GetProcessList for the same view SM51 shows inside SAPGUI.

8/06/2020

The TAR command | Bash Basics


If you are familiar with ZIP, then you will be familiar with TAR. Basically, this is used to archive files into a single, hopefully, smaller, file. Sometimes you will hear these referred to as a “tarball”.

Figuring out what is in a TAR Archive

So normally when you are provided with a “tarball”, you go get it and then you extract it onto your system. This raises the questions, where will the files be created and what will be created? We can inspect the .tar file to determine what is in it. Remember that when we are working with TAR, we want it to be Verbose and so we add the v flag so we can see what it is doing. In the case of listing the contents of the archive, adding verbose or v is the same as asking for a long listing in the ls command by adding -l.
tar --list --verbose --file 
Ok, let’s get real, no one does this; this is what it would look like if you read the man page and decided that you wanted to type all of the things. I am lazy and I like to get things done with the least amount of typing on my part. What you see here is the same as this:
tar -tvf 
The only odd thing here is that --list is replaced by -t and then we can add all the flags to the same - statement. This means that for the rest of the examples I will show you the shorthand and you can decide how you want to do it. So now let’s look at some actual output.
$ tar -tvf ./example.tar 
drwxr-xr-x  0 mmcclaren staff       0 May  2 14:37 ./example/ 
-rw-r--r--  0 mmcclaren staff     210 May  2 14:23 ./example/._examplefile1 
-rw-r--r--  0 mmcclaren staff     899 May  2 14:23 ./example/examplefile1 
-rw-r--r--  0 mmcclaren staff     210 May  2 14:23 ./example/._examplefile2 
-rw-r--r--  0 mmcclaren staff   15033 May  2 14:23 ./example/examplefile2 
-rw-r--r--  0 mmcclaren staff     210 May  2 14:23 ./example/._examplefile3 
-rw-r--r--  0 mmcclaren staff   14957 May  2 14:23 ./example/examplefile3 
In this case, we can see that all of the example files were included in an example directory. This means that when we extract this, we will get that directory in the output. If the path is only the files and there is not a directory included, then the files will end up in the directory that you are in, unless you specify an extraction point.

Extracting a TAR Archive

So now that we know what is in there, we want to get it out of there. This is a matter of running the eXtract flag and the File flag.  Remember that we can add the Verbose flag so that we can see what it is working on.
 $ tar -xvf ./example.tar  
 x ./example/ 
 x ./example/._examplefile1 
 x ./example/examplefile1 
 x ./example/._examplefile2 
 x ./example/examplefile2 
 x ./example/._examplefile3 
 x ./example/examplefile3 
In this example, we extract the files into the example directory.
 $ ls -l ./example 
 total 72 
 -rw-r--r--@ 1 mmcclaren  staff    899 May  2 14:23 examplefile1 
 -rw-r--r--@ 1 mmcclaren  staff  15033 May  2 14:23 examplefile2 
 -rw-r--r--@ 1 mmcclaren  staff  14957 May  2 14:23 examplefile3 
If we wanted to indicate where we wanted the archive extracted, this would require the addition of the -C flag and a location as an argument. Think of this as “copy” the extracted files to the location indicated.
 $ tar -xvf ./example.tar -C ./location 
 x ./example/ 
 x ./example/._examplefile1 
 x ./example/examplefile1 
 x ./example/._examplefile2 
 x ./example/examplefile2 
 x ./example/._examplefile3 
 x ./example/examplefile3 
 $ ls -l ./location 
 total 0 
 drwxr-xr-x  5 mmcclaren  staff  160 May  2 15:08 example 
And the last thing that I want to talk about is extracting only one file from the archive. This takes the form of tar -xf ( archive name ) ( file name ) as in this example.
 $ tar -xvf ./example.tar ./example/examplefile2 
 x ./example/examplefile2 
 $ ls 
 example example.tar location 
 $ ls ./example 
 examplefile2 

Creating an Archive

Whew, this is a long one! We cannot leave, though, without knowing how to create an archive. The simplest way is to point TAR at a directory and use the -c flag for Create in the form of:
tar -cf  
This is how the example archive that we have been using was created:
 $ tar -cvf example.tar example 
 a example 
 a example/examplefile1 
 a example/examplefile2 
 a example/examplefile3 
 $ tar -tf ./example.tar  
 example/ 
 example/._examplefile1 
 example/examplefile1 
 example/._examplefile2 
 example/examplefile2 
 example/._examplefile3 
 example/examplefile3 
One last thing: let’s add a file to an existing archive. The -r flag is used to append to the directory and it takes the same syntax as “create”; the name of the archive and then the file.
$ tar -rf example.tar examplefile4 
$ tar -tf example.tar
example/
example/._examplefile1
example/examplefile1
example/._examplefile2
example/examplefile2
example/._examplefile3
example/examplefile3
examplefile4
As you can see, the examplefile4 was added to the previous archive that we have been using.

How to exit from VIM (VI) ?

Have you or a loved one ever had to reboot your computer to get out of a read-only file in VIM?

  • Are you responsible for a Linux system or set of systems where a graphical editor or adding new editors is prohibited?
  • Are you taking an online training course where all the labs use the VIM editor, and it’s driving you crazy?
  • Do other Open Source Pros tease you about not knowing VIM?
This short tutorial will help you get past the main issues you might encounter in quitting VIM. 

Use this tutorial to safely quit VIM, without the headaches

First off, you need to know what user you are when you edit files with VIM, so at the command line enter the id command:

IMPORTANT: One of the keys to not getting stuck in VIM is to never edit a root-only file as a regular user.  If you are the system admin, look into using the sudo command to allow editing root-only files from a regular account safely!

If you are in VIM and cannot seem to quit, we’ve got your back!  Relax, grab a drink of water, and let’s walk through a few very common scenarios.
Scenario #1
You are editing a root-only file as a regular user, have made changes to the file/buffer and it won’t let you out, showing you a message like this:
Solution #1
Press the ESC key twice or until you hear the “error bell”, then press :qa! which will force quit all open files/buffers and take you back to the command line.
Scenario #2
While trying to quit VIM with the keystrokes :q, you suddenly find the lower portion of your screen looks like a history list of the commands you’ve issued recently in VIM, and it freaks you out.
Solution #2
You have accidentally used the keystrokes q:, which opens up a Lastline or CommandLine history mode window that you could choose previous commands from to execute them again.  You can close this by carefully pressing :q again, which puts you back into Command/Normal Mode and you can quit as you would normally.
Scenario #3
You have tried to force-quit the file/buffer using :q! and suddenly you find yourself in what appears to be the command line, but it’s telling you that the q: command is not found.
Solution #3
You’ve flipped the keystrokes around and entered :!q, which is telling the VIM editor that you want to run an external command (:!command) and of course it won’t find the q: command, so all you get is an error!  Press ENTER and you’ll be back inside VIM and can exit normally, just be careful to type exactly what you want!

VI Shortcuts & Commands For Newbies

This is a collection of some of the basic VI commands and shortcuts for newbies. You’ll find yourself needing this if you are coding or scripting inside of the unix/linux command line using VI.
Command Mode: Accepts commands, which are usually in the form of individual letters. Example, a and i.
You can use h, j, k and I to navigate in similar ways as the up and down arrow. Not needed if you have an up and down arrow on your keyboard.
Yank – Term used to copy files. Use YY to yank text. Navigate to the line you wish to yank and type yy make sure you are in command mode.
2yy will yank 2 lines, 4yy will yank 4 lines. Precede the YY command with the number of lines you would like to yank.

a – append text after cursor
A – append text to end of current line
p – Command will paste the yanked line(s) contents starting on the line after your cursor.
P – Upper case P will paste the yanked line(s) starting on the line before our cursor
G – Takes you to specified line
H – Takes the cursor to the top of the page
L – Takes the cursor to the bottom of the page
o – inserts a new line below the line your cursor is on and inserts into insert mode for typing.
u – undo any change, must be in command mode and only goes back one change.
w – Move over one word at a time
Shift + G– Takes you to the bottom of the page
Page up and down in VI
Shift + f Page down (forward)
Shift + b page up (backward)
note* The keyboard page and and page down keys work the same
Change text – cc-allows you to change the entire line (basically removes the line and inserts into insert mode) cw to replace just one word on the line the current word your mouse is over.
Search – search forward type / and ? searches backwards; both followed immediately by the term to search for.
:%s/foo/bar will replace the first occurrence of foo with bar, operating on every line in the buffer.
:%s/foo/bar/g will replace every occurrence of foo with bar, operating on every line in the buffer.
:s/foo/bar will replace the first occurrence of foo with bar, operating on the current line.
:s/foo/bar/g will replace every occurrence of foo with bar, operating on the current line.

Also very helpful is the /c flag – it will allow you to confirm each replacement match, depending on the above criteria for searching.

n – moves to next occurrence of search string
N – move to next occurrence of search string in opposite direction
Ex mode: Enter ex mode from command mode with “:”. Use this to save or manipulate files. This mode is also referred to as colon commands
Replace text – :%s/fine/ one – this replaces all occurs of “fine” with “one”
% represents “global changes to all occurrences” replace to a line number, ending line number of comma.
:= – returns number of current line
:w filename – writes contents of file to a new filename.
Insert Mode: Enables you to insert and edit text. The Esc key exits insert mode and returns you back to command mode.
R – enters the insert mode to replace text not insert text. It will replace text until it hits a space. After a space you must start typing over the text for it to apply or it will just push text down.
i – used to insert text and not replace it. Pushes existing text down.
ZZ– Save and quit in 2 key strokes instead of wq!
:w – Saves changes without quitting
:wq – Saves changes and quits
:q! – Quits without saving changes.
:e /file.txt will load the new file.txt into the vi editor for editing. This will only occur if the current changes to the current file being edited are saved.
:r allows you to bring contents of an old file into a new one.
:! Allows you to run shell commands from within vi. Such as :!mkdir tes

The Linux find Command

We get so focused on the super-advanced things that Linux can do, that we tend to forget about or glaze over the mundane.  Linux’s find command falls into that category for me.
First of all, remember that Linux is case sensitive. This means that “TEST”, “test”, “Test”, and “TesT” all register as completely different files. Run find –help for all of the available options. To see everything, including the things I’m not going to cover in this brief article, remember you can always man find.
Examples:
Find all files in the entire system that are named test.txt:
find / -name “test.txt”
Find all files in the /etc directory not named test.txt:
find /etc/ -not -name “test.txt”
Find all character devices on the system:
find / -type c
Find all directories called log:
find / -type d -name “log”
Find all files in the /usr/bin directory or subdirectories that are larger than 27,000 bytes:
find /usr/bin/ -size +27000c or find /usr/bin -size +27k
Find all files in the /usr/bin directory or subdirectories that are larger than 1 megabyte:
find /usr/bin/ -size 1M
Find all files created more than a day ago:
find / -mtime 1
Find all files create less than a day ago:
find / -mtime -1
Find all files owned by the user named “chad”:
find / -user chad
Find all files in the /etc directory owned by the user root, and paginate:
find /etc/ -user root | more
Find all files in the /usr/bin directory with the user permissions 755:
find /usr/bin/ -perm 755
Find all files called test.txt and set their permissions to 700:
find / -name “test.txt” -exec chmod 700 {} \;
In Linux, the general rule is “No news is good news,” which means that when a command completes successfully, you will likely receive no command line confirmation or other feedback. If you don’t get a response to a command, it likely completed exactly as you expected.
The more command will cause the output to pause after it fills a page and waits for you to hit the space bar before continuing. There is also a less command that will allow you to scroll back and forth through the output using arrow keys.
The which command allows you to find the version of a command that will be executed if invoked. This is useful for locating the executable file, especially if the behavior is not what you expected. For instance, to find out which python executable would be invoked, run:
which python
The locate command can also help you find files but relies on a database rather than looking directly at the file system. The two can easily be out of sync. To synchronize the locate’s database, run the command (as root):
updatedb

Linux Commands For Beginners: SUDO

Sudo, the one command to rule them all.  It stands for “super user do!”  Pronounced like “sue dough” As a Linux system administrator or power user, it’s one of the most important commands in your arsenal.  Have you ever tried to run a command in terminal only to be given “Access Denied?”  Well this is the command for you!  But, with great power comes great responsibility!  It is much better than logging in as root, or using the su “switch user” command.  Read on to see what sudo can do for you!

SUDO: What is it good for?

So what does sudo actually do?  If you prefix “sudo” with any linux command, it will run that command with elevated privileges.  Elevated privileges are required to perform certain administrative tasks.  Someday you may wish to run a LAMP (Linux Apache MySQL PHP) server, and have to manually edit your config files.  You might also have to restart or reset the Apache web server or other service daemons.  You even need elevated privileges to shutdown or restart the computer.  “Hey, who turned this thing off?!”
If you are familiar with Windows, it is very similar to the Windows User Account Control dialog box that pops up when you try to do anything important, just not as friendly.  In Windows, if you try to perform an administrative task, a dialog box asks you if you wish to continue (“Are you really sure your want to run that program you just clicked on?”).  The task is then performed.  On a Mac, a security dialog box pops up and you are required to type in your password and click OK.
It is more of a dramatic story in Linux.  Things might behave quite strangely without the proper permissions.  The important config file you were editing may not save correctly.  A program you installed may simply refuse to run.  That awesome source code you downloaded and need to compile, wont.  You might even be lucky enough to given an “Access Denied” or another friendly error message. All your worst fears have come true, but all you needed to do was ask for permission!  That is why we want to remember to ask for superuser permissions upfront like this:
sudo reboot
Watch what happens in this screenshot if we don’t first elevate our permissions with sudo:
reboot
First we use the reboot command to try and reboot the system.  The command fails citing: “must be superuser”.  We then try with sudo reboot.  Sudo asks for your user password.  Note that it is asking for your password, not the root password.  Finally we see the broadcast message that the system will be rebooted now.  Sudo is like saying the magic word.  It might as well be named opensesame or abracadabra or even bippityboppitybacon.
sandvich

Why is it better than the alternative?

Sudo is the best and safest way to elevate privileges.  Lets take a look at another way of doing things.  The switch user command, “su” will ask you for the root password and give you a superuser prompt, signified by the # symbol.  That # symbol means “DANGER! YOUR LOGGED IN AS ROOT!”  The first command you issue may go well.  But your forgetfulness will cause you to stay logged in as root.  One bad typo and BAM!  You erased the entire hard drive instead of that fake mp3 you downloaded.  The cat decides to lay on your nice warm laptop.  POOF!  Your web server and home business are gone!  With the sudo command, you have to enter in “sudo” before every command.  Thus you don’t have to remember to switch back to regular user mode, and fewer accidents will happen.

The Sudoers File

This file is the seedy underbelly of sudo.  It controls who can use the sudo command to gain elevated privileges.  It is usually located at /etc/sudoers.  The best and safest way to edit this file is by using the visudo command.  This command will start the vi editor with elevated privileges so that you can edit the file and save it.  It also will put a filelock on the sudoers file so that no one else can edit it.  Once your done editing it, it will parse the file for simple errors.  It is a much safer way of editing the sudo file than just using any old text editor.
This file contains many parameters.  You can specify which users of which groups can perform what commands.  We are simply going to grant ourselves access to sudo by adding:
username   ALL=(ALL)       ALL //gives user "username" sudo access
%wheel     ALL=(ALL)       ALL //Gives all users that belong to the wheel group sudo access
at the bottom.  Now the specified username will be able to use all root privileges. You can also allow a user or group to have sudo access to only specific services or servers in replace of the ALL parameter, but, that’s a topic for another day.

Some Options

Like any good command there are a few nifty options to make sudo, do more!
sudo –b will run the command in the background.  This is useful for commands that display a lot of output as they are running.
sudo –s will run the shell specified with elevated privlages, giving you the # prompt (don’t forget to exit!)
sudo su – will make you the root user and load your custom user environment variables.

Changing The Time Zone In Linux (Command Line)

There are several different ways to manage time in Linux. This quick tip will show you how to quickly change the local time to the correct time zone for the server. In this Linux tip I’ll show you how to change the localtime to your (or a) current time zone.
Location of the local time file
Linux looks at /etc/localtime to determine the current time of your machine. This can either be a symbolic link to the correct time zone or a direct copy of the time zone file.

Timezone files are located in /usr/share/zoninfo/
For this tip we will assume your server is located in America and will be under the Chicago CST zone.
I change the Linux time zone by copying or making a symbolic link to from /usr/share/zoneinfo/America/Chicago to /etc/localtime
Two methods to do this
cp /usr/share/zoneinfo/America/Chicago /etc/localtime

ln -s /usr/share/zoneinfo/America/Chicago /etc/localtime

Type w to change the new time and you’re done!

Popular Posts